Simple recursive solution


  • 0
    D
    class Solution(object):
        def grayCode(self, n):
            if n == 0:
                return [0]
            prev = self.grayCode(n-1)
            return prev + [2**(n-1) + x for x in reversed(prev)]

Log in to reply
 

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