class Solution:
    def grayCode(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        times,number=0,1
        res=[0]
        while times<n:
            temp=res.copy()
            temp.reverse()
            for i in range(len(temp)):
                temp[i]+=number
            res+=temp
            number*=2
            times+=1
        return res