Share my python solution (67ms)


  • 0
    M
    class Solution:
        # @return a list of integers
        def grayCode(self, n):
            if n==0:
                return [0]
            elif n==1:
                return [0, 1]
            else:
                gray_n_1 = self.grayCode(n-1)
                gray_n = gray_n_1[:]
                for item in reversed(gray_n_1):
                    gray_n.append(2**(n-1)+item)
                return gray_n

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.