leetcode89

感情迁移 提交于 2019-12-11 13:00:26
1 class Solution:
2     def grayCode(self, n: int) -> 'List[int]':
3         gray = [0]
4         for i in range(n):
5             # reflect, add leading 1, and concatenate
6             gray.extend([(1 << i) + x for x in gray[::-1]])
7         return gray

这是一道数学题,参考:https://leetcode.com/problems/gray-code/discuss/445279/Python-solution

不了解这个数学原理的,面试时很难做出来。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!