leetcode-89-格雷编码*
题目描述:
方法一:
class Solution: def grayCode(self, n: int) -> List[int]: gray = [0] for i in range(n): add = 2**i for j in range(len(gray)-1,-1,-1): gray.append(add+gray[j]) return gray
方法二:
class Solution: def grayCode(self, n: int) -> List[int]: res = [] for i in range(2 ** n): res.append((i >> 1) ^ i) return res