We add 2^i to the corresponding number in the reversed copy of the previous array, then append it to the array each time.

```
class Solution:
# @return a list of integers
def grayCode(self, n):
a = [0]
for i in range(n):
a += list(x + 2**i for x in a[::-1])
return a
```