#Leet Code# Gray Code
描述:
要求相邻数2进制差一位
先获得n-1的列表表示小于 2^(n-1) 的符合要求的列表,加上最高位的加成 2^(n-1) 就是大于等于 2^(n-1) 的符合要求的列表,后者翻转一下就能够与前者连接上了
代码:
class Solution:
# @return a list of integers
def grayCode(self, n):
if n == 0: return [0] s1 = self.grayCode(n - 1)
s2 = [item + 2 ** (n - 1) for item in s1[::-1]]
s1.extend(s2) return s1
#Leet Code# Gray Code的更多相关文章
- 89. Gray Code(中等,了解啥是 gray code)
知道啥是 gray code 就是收获了. 下面介绍了 gray code 发明的 motivation, 了解动机后就知道啥是 gray code 了. https://zh.wikipedia.o ...
- [LeetCode] Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- 【LeetCode】Gray Code
Gray Code The gray code is a binary numeral system where two successive values differ in only one bi ...
- Gray Code
Gray Code The gray code is a binary numeral system where two successive values differ in only one bi ...
- 【leetcode】Gray Code (middle)
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- [LintCode] Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- 44. Decode Ways && Gray Code
Decode Ways A message containing letters from A-Z is being encoded to numbers using the following ma ...
- LeetCode——Gray Code
Description: The gray code is a binary numeral system where two successive values differ in only one ...
- LeetCode:Gray Code(格雷码)
题目链接 The gray code is a binary numeral system where two successive values differ in only one bit. Gi ...
随机推荐
- VBScript
VBScript then PrintWMIErrorthenExit Err.Description, Err.Number else ifnot boolCathiMode then wscrip ...
- 文件I/O(不带缓冲)之I/O的效率
程序清单3-3中的程序使用read和write函数复制文件.关于该程序应注意下列各点: 它从标准输入读,写至标准输出,这就假定在执行本程序之前,这些标准输入.输出已由shell安排好.确实,所有常用的 ...
- 实例源码--Android简单团购应用源码
下载源码 技术要点: 1.HTTP通信技术 2.XML数据解析 3.控件的简单应用 4.源码带有非常详细的中文 注释 ...... 详细介绍: 1. HTTP通信技术 通 过HTTP通信技术, ...
- C#_MVC 自定义AuthorizeAttribute实现权限管理
随笔- 28 文章- 31 评论- 16 MVC 自定义AuthorizeAttribute实现权限管理 在上一节中提到可以使用AuthorizeAttribute进行权限管理: [Autho ...
- Using zend-paginator in your Album Module
Using zend-paginator in your Album Module TODO Update to: follow the changes in the user-guide use S ...
- 结合 category 工作原理分析 OC2.0 中的 runtime
绝大多数 iOS 开发者在学习 runtime 时都阅读过 runtime.h 文件中的这段代码: struct objc_class { Class isa OBJC_ISA_AVAILABILI ...
- hibernate3整合spring2时hibernate即用注解又用配置文件情况时spring配置文件的配置写法
hibernate只用注解时,spring的配置文件的配置如下 <bean id="dataSource" class="org.apache.commons.db ...
- python--for循环
1.循环输出1-10 for i in range(1,11): print(i) 1 2 3 4 5 6 7 8 9 10 2.break用法,break为跳出整个当前循环层,只跳一层.当i=5的时 ...
- 多边形节点编码python脚本
# -*- coding: cp936 -*-#本脚以最左边.Y值最大的点为起始点按顺时针为多边形节点编码,生成一个包含记录编码值和多边形FID字段的点要素类 #注意:#1.本脚本作为arcgis脚本 ...
- nmblookup
域网内可以通过下述命令来根据ip地址查询其他主机名(Linux) 使用nmblookup -A ip命令查询 [admin@v015213 ~/lpmall]$ nmblookup -A 10.19. ...