class Solution(object):
def grayCode(self, n):
"""
:type n: int
:rtype: List[int]
"""
if n==0:
return [0]
ret=[0,1]
for i in xrange(1,n):
prev=2**i
lastind = len(ret)-1
for v in xrange(lastind+1):
ret.append(ret[lastind-v]+prev)
return ret