博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[leetcode]Gray Code @ Python
阅读量:7036 次
发布时间:2019-06-28

本文共 819 字,大约阅读时间需要 2 分钟。

原题地址:https://oj.leetcode.com/problems/gray-code/

题意:

The gray code is a binary numeral system where two successive values differ in only one bit.

Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.

For example, given n = 2, return [0,1,3,2]. Its gray code sequence is:

00 - 001 - 111 - 310 - 2

Note:

For a given n, a gray code sequence is not uniquely defined.

For example, [0,2,3,1] is also a valid gray code sequence according to the above definition.

For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.

解题思路:格雷码的生成,采用数学的方法。

代码:

class Solution:    # @return a list of integers    def grayCode(self, n):        res=[]        size=1<
>1)^i) return res

 

转载地址:http://ahjal.baihongyu.com/

你可能感兴趣的文章
记一次文件转换服务升级"笔录"
查看>>
盛科网络完成3.1亿战略融资 国家集成电路产业投资基金领投
查看>>
瑞士太阳能飞机项目发起人: 在全球寻找1000个环保解决方案
查看>>
5G为新的颠覆性市场领导者敞开大门
查看>>
最高法“法信”大数据平台上线
查看>>
政府在大数据问题上不要大包大揽 要充分尊重市场规律
查看>>
硅芯片已经 OUT 了?韩国推出超环保“纸制芯片”
查看>>
智能存储解决方案需求为啥高?
查看>>
云存储解决方案日趋多样化
查看>>
IDC预测:2020年SDN市场规模将达到125亿美元
查看>>
看“风水反转”技术如何危害云安全
查看>>
密码重用的危害及规避方法
查看>>
致25岁的你:看看这些IT大佬 你还会放弃你的梦想吗
查看>>
英国发明睡眠传感器,助力改善睡眠质量
查看>>
传统家电品牌布局高端智能家居
查看>>
Ponemon Institute告诉你,大数据正在勾搭网络安全
查看>>
使用Jazz Automation编写自动化测试
查看>>
松下要造懒人必备智能家居:用平板指挥微波炉
查看>>
Colt进行网络升级 提供100Gbps光纤服务
查看>>
Php常用代码数据库的连接及读取和写入
查看>>