Gray Code LeetCode solution in Python
1import math234class Solution(object):5def grayCode(self, n):6"""7:type n: int8:rtype: List[int]9"""10allowedDiffs = [int(1 * math.pow(2, i)) for i in range(0, n)]11grayCodes = [0]12for diff in allowedDiffs:13grayCodes += [code + diff for code in reversed(grayCodes)]14return grayCodes