题目的意思就是将十进制转换成格雷码

首先将二进制转换成格雷码

根据此图可以看出二进制的第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的更多相关文章

  1. [LeetCode] Gray Code 格雷码

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  2. [leetcode]Gray Code @ Python

    原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...

  3. LeetCode——Gray Code

    Description: The gray code is a binary numeral system where two successive values differ in only one ...

  4. LeetCode:Gray Code(格雷码)

    题目链接 The gray code is a binary numeral system where two successive values differ in only one bit. Gi ...

  5. LeetCode: Gray Code [089]

    [题目] The gray code is a binary numeral system where two successive values differ in only one bit. Gi ...

  6. LeetCode: Gray Code 解题报告

    Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit ...

  7. [转载]LeetCode: Gray Code

    The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...

  8. [LeetCode]题解(python):089 Gray Code

    题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two suc ...

  9. 【一天一道LeetCode】#89. Gray Code

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 The gra ...

随机推荐

  1. [java] 可视化日历的实现(基于Calendar类 )

    写在前面 博文安排顺序如下 1.写在前面 2.源码 3.思路 4.相关知识 该小程序是对Date类及其相关类的复习 要求如下图:实现可视化日历 实现思路 1.先从键盘输入指定格式的字符串(str)2. ...

  2. 改进你的WordPress导航菜单 —— 输出标题描述

    在WordPress 3.0中增加了自定义菜单功能,如果你在WordPress后台(外观>菜单)创建一个菜单,你可以在主题中使用wp_nav_menu()函数来显示这些菜单.但是像图中这种带描述 ...

  3. FreeCodeCamp练习笔记

    CSS样式表: 嵌套:body是最外层包围其他所有HTML元素(标签),其中的元素样式都可覆盖body的样式. 覆盖:同一元素有多个样式,位置靠后的样式覆盖位置靠前的样式. id:id与位置无关,可任 ...

  4. [Kerberos] Kerberos 认证过程整理

    Kerberos是一种安全认证协议,意在提供 more secure authentication simplified management of password convenience of s ...

  5. Ulink2 "No Ulink Device found" 解决办法

    一.背景 keil使用ULINK2调试的时候,提示 "No Ulink Device found", "error: flash download failed - Ta ...

  6. mac 上的 python

    1.mac 上的 python 自己感觉很乱 1.额外安装的 自带的 python27-apple /System/Library/Frameworks/Python.framework/Versio ...

  7. jQuery入门(2)使用jQuery操作元素的属性与样式

    jQuery入门(1)jQuery中万能的选择器 jQuery入门(2)使用jQuery操作元素的属性与样式 jQuery入门(3)事件与事件对象 jQuery入门(4)jQuery中的Ajax()应 ...

  8. CentOS 安装tomcat 7

    安装环境:CentOS-6.3 安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址:http://tomcat.apache.org/download-70.c ...

  9. 及时取消代码中的AsyncTask

    在一个Activity页面,如果发起了AsyncTask任务,然后页面离开/销毁了,此时如果doInBackground没执行完,会有两个问题: 1, AsyncTask白白消耗资源,结果已经用不上了 ...

  10. rsa 签名 加密解密

    A->B 签名 ==========================A方+A方的私钥 => B收到后 用A方的公钥 验证签名 ==========================A-> ...