Gray Code LeetCode solution in Python

1
import math
2

3

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0