Gray Code
来源:互联网 发布:淘宝强行退款 编辑:程序博客网 时间:2024/06/05 22:44
------QUESTION-----
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer
For example, given [0,1,3,2]
. Its gray code sequence is:
00 - 0 01 - 1 11 - 3 10 - 2
Note:
For a given
For example, [0,2,3,1]
For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.
------SOLUTION-----
class Solution {public: vector<int> grayCode(int n) { vector<int> result; int size = 1 << n; for (int i =0; i< size; i++) { result.push_back(getGrayCode(i)); } return result; } int getGrayCode(int binary) { return ((binary >> 1)^binary); }};
0 0
- Gray Code
- Gray Code
- gray code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- Gray Code
- ISA95的抽象惯例
- ffplay parameters
- poj 1258 Agri-Net(最小生成树,普里姆算法)
- ios--MBProgressHUD(使用方式一)--在事件的执行过程中显示+指定显示时间长短
- TIANKENG’s restaurant
- Gray Code
- ArcGis for android 加载tpk离线文件(http://blog.csdn.net/vpingchangxin/article/details/8778869)
- hdu 4893 线段树+二分fib
- Spring AOP(面向切面编程)【Spring AOP的技术基础】
- 分享:APK高级保护方法解析(一)
- 关于二进制补码
- 把字符串转换为整数
- Business Rules(From Wiki)
- java.util.RandomAccessSubList cannot be cast to java.util.ArrayList解决办法