Leetcode Gray Code
题目的意思就是将十进制转换成格雷码
首先将二进制转换成格雷码

根据此图可以看出二进制的第i和第i+1位异或为格雷码的第i+1位,对于给定的十进制数x,其(x>>1)相当于二进制向右移动一位
将 x^(x>>1)刚好能按照上述方式完成异或,故结果为x的格雷码
class Solution {
public:
vector<int> grayCode(int n) {
vector<int> res;
for(int x = ; x< (<<n);++ x) res.push_back(x^(x>>));
return res;
}
};
Leetcode Gray Code的更多相关文章
- [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 @ Python
原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...
- 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 ...
- LeetCode: Gray Code [089]
[题目] The gray code is a binary numeral system where two successive values differ in only one bit. Gi ...
- LeetCode: Gray Code 解题报告
Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit ...
- [转载]LeetCode: Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- [LeetCode]题解(python):089 Gray Code
题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two suc ...
- 【一天一道LeetCode】#89. Gray Code
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 The gra ...
随机推荐
- TypeError: 'bool' object is not callable g.user.is_authenticated()
此问题查了stackoverflow后知道is_authenticated是一个属性而不是一个方法所以g.user.is_authenticated() 用法会报错
- github上readme.md 格式
参考:https://github.com/guoyunsky/Markdown-Chinese-Demo/edit/master/README.md
- read name 和 read 在 Bash 中的区别
read 带一个参数和不带参数的区别是什么,我本以为仅仅是被赋值的变量的名字不同而已: $ read name 1 $ echo "$name" 1 $ read 1 $ echo ...
- PHP简单 对象(object) 与 数组(array) 的转换
数组是PHP的灵魂,非常强大,但有时候面向对象编程也是挺方便的,数组 与 对象 之间切换也是常有的事: /** * 数组 转 对象 * * @param array $arr 数组 * @return ...
- Linux 等待进程结束 wait() 和 waitpid()
若子进程先于父进程结束时,父进程调用wait()函数和不调用wait()函数会产生两种不同的结果: --> 如果父进程没有调用wait()和waitpid()函数,子进程就会进入僵死状态. -- ...
- 编译安装 Zend Opcache 缓存Opcache,加速 PHP
Optimizer+ 是 Zend 开发的闭源但可以免费使用的 PHP 优化加速组件,是第一个也是最快的 opcode 缓存工具.现在,Zend 科技公司将 Optimizer+ 在 PHP Lice ...
- 深度学习入门教程UFLDL学习实验笔记三:主成分分析PCA与白化whitening
主成分分析与白化是在做深度学习训练时最常见的两种预处理的方法,主成分分析是一种我们用的很多的降维的一种手段,通过PCA降维,我们能够有效的降低数据的维度,加快运算速度.而白化就是为了使得每个特征能有同 ...
- django 模板语法和三种返回方式
模板 for循环 {% for athlete in athlete_list %} <li>{{ athlete.name }}</li> {% endfor %} if语句 ...
- Python dir
1. 在python命令行交互环境下,可以用dir()函数查看当前的变量,比如: >>> dir()['__builtins__', '__doc__', '__loader__', ...
- OSSFS将OSS bucket 挂载到本地文件系统及注意事项
OSSFS将OSS bucket 挂载到本地文件系统及注意事项 下载ossfs安装包 wget http://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/as ...