411
来源:互联网 发布:有声照片软件 编辑:程序博客网 时间:2024/06/08 07:22
2017.10.20
格雷编码,最主要的就是要了解编码产生的过程。
这段是抄别人的,哈哈哈:如n=2时,格雷码为00,01,11,10.如需生成n=3的格雷码只需先将原序列高位加0变成000,001,011,010,再将原序列在高位加1并逆向添加到刚才生成的序列尾部,即000,001,011,010,110,111,101,100。也就是说,n+1位元格雷码是基于n位元格雷码产生的。
public class Solution { /* * @param n: a number * @return: Gray code */ public List<Integer> grayCode(int n) { // write your code hereList<Integer> res = new LinkedList<>();if(n == 0){ res.add(0);return res;}if(n == 1){ res.add(0);res.add(1);return res;}List<Integer> list = grayCode(n-1);for(int i = 0 ;i < list.size(); i++){res.add(list.get(i));}int add = (int)Math.pow(2, n-1);for(int i = list.size() - 1; i >= 0; i--){res.add(list.get(i) + add);}return res; }}
阅读全文
0 0
- 411
- 411
- ocp-411
- codefoces #411
- http 411错误
- gitlab 411 413错误
- nyoj 411-Friends number
- 411高校毕业设计选题
- nyoj 411 Friends number
- hadoop学习笔记411
- ocp053第411题
- #411 Gray Code
- 求职准备411
- Codeforces Round #411
- codeforce round#411div2
- SGU 411 Petya the Hero
- git的Http错误411
- CodeForces 411A Password Check
- Python版课堂管理系统中使用UDP广播远程关闭客户端程序思路与源码
- QSerailPort使用readAll()接收数据不全问题解决
- Python快速教程
- 更难的矩阵取数问题
- android 输入法弹出把dialog顶上去并退出闪屏
- 411
- OpenGL学习笔记——半反射,反射贴图
- window+ubuntu双系统安装 tensorflow
- 【html5】transform属性
- python 用(%s%d)格式化字符串与用format格式化的区别
- 还没吃上奥利奥,谷歌Android 8.1竟要来了。。。
- HashMap、HashTable、HashSet
- shell 脚本中中-f -e -eq等等的意义
- JS_BOM笔记