AC Python 44ms solution


  • 2
    def grayCode(self, n):
        ans = [0]
        for i in xrange(n):
            for j in xrange(len(ans) - 1, -1, -1):
                ans.append(1 << i | ans[j])
        return ans
    
    
    # 12 / 12 test cases passed.
    # Status: Accepted
    # Runtime: 44 ms
    # 92.86%
    

    Append a bit of 1 in front of on every number to generate next batch.


Log in to reply
 

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