Question: https://oj.leetcode.com/problems/gray-code/
Question Name: Gray Code
At the beginning, I have no idea other than brute force. But thanks to Wikipedia, the perfect solution is found.
1 2 3 4 5 6 7 | class Solution: # @return a list of integers def grayCode(self, n): result = [] for item in xrange(1<<n): result.append(item ^ (item>>1)) return result |