Gray Code - Leetcode
来源:互联网 发布:ios开发 耗电量优化 编辑:程序博客网 时间:2024/05/21 18:33
public class Solution { public List<Integer> grayCode(int n) { List<Integer> result = new ArrayList<>(); int size = 1<<n; for(int i=0; i<size; i++){ result.add(i^(i>>1)); } return result; }}
分析:当前值右移,异或当前值
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.
0 0
- LeetCode: Gray Code
- [LeetCode] 格雷码(Gray Code)
- LeetCode Gray Code
- [Leetcode] Gray Code
- [LeetCode] Gray Code
- leetcode 112: Gray Code
- LeetCode Gray Code
- [leetCode] Gray Code
- [LeetCode]Gray Code
- Leetcode: Gray Code
- [leetcode]Gray Code
- LeetCode-Gray Code
- [leetcode] Gray Code
- LeetCode - Gray Code
- leetcode之Gray code
- LeetCode:Gray Code
- 【转载】【leetcode】Gray Code
- LeetCode - Gray Code
- 非安全传输协议前提下,Open API安全协议设计
- 管理学定律十:罗森塔尔效应与虚假同感偏差
- android仿iphone的地区选择
- 仿支付宝手势密码
- 仿iphone快速导航悬浮球
- Gray Code - Leetcode
- LDA算法入门
- ccflow (ccoa)修改菜单
- Android 开发中Handle 没有handleMessage方法
- 算法导论:快速排序代码
- linux驱动开发之前篇1
- Javascript 将 ThinkPHP 分页自动转换为 bootstrap 分页
- 堆和栈的区别(转过无数次的文章)
- 2014博客之星,感激自己,谢谢大家