Gray Code

Given an integer n, return a Gray code cycle of length 2^n: an array containing every integer from 0 to 2^n - 1 exactly once, starting at 0, where every adjacent pair differs by exactly one bit in binary. The pair formed by the last and first elements must also differ by exactly one bit, so the sequence closes into a cycle.

Any valid cycle starting at 0 is accepted. The result does not have to be the binary reflected Gray code.

Examples
Input: 1
Output: [0,1]
Hints

Gray Code

Given an integer `n`, return a Gray code cycle of length `2^n`: an array containing every integer from `0` to `2^n - 1` exactly once, starting at `0`, where every adjacent pair differs by exactly one bit in binary. The pair formed by the last and first elements must also differ by exactly one bit, so the sequence closes into a cycle.