Simple Python Backtracking Method 52 ms

  • 0
    class Solution(object):
        def grayCode(self, n): 
            if n==0: return [0]
            return self.back(n) 
        def back(self, n):
            if n==1:
                return [0,1] 
            cur = [] 
            pre= self.back(n-1)
            for x in xrange(len(pre)-1,-1,-1):
            return pre+cur

Log in to reply

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