```
class Solution(object):
def grayCode(self, n):
"""
:type n: int
:rtype: List[int]
"""
if n < 1:
return [0]
ret = [0, 1]
for i in xrange(1, n):
r_seq = [j ^ 2**i for j in reversed(ret)]
ret.extend(r_seq)
return ret
```