麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

[leetcode]89. Gray Code

2019-11-14 09:35:46
字體:
供稿:網(wǎng)友

題目鏈接:https://leetcode.com/PRoblems/gray-code/

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.

 解題思路:

手動地列出n=3時候的情況,會發(fā)現(xiàn)。n=3的結(jié)果如下:

000001011010  ↑--------110  ↓111101100

可看成是上下對稱的2部分。上半部分是n=2時候的結(jié)果再在最高位加"0"的結(jié)果。下半部分是n=2時候的結(jié)果逆序之后再在最高位加"1"的結(jié)果。

class Solution{public:    vector<int> grayCode(int n)    {        vector<int> res;        res.push_back(0);        if(n==0)            return res;        for(int i=1;i<=n;i++)        {            for(int j=res.size()-1;j>=0;j--)            {                res.push_back(res[j]+pow(2,i-1));            }        }        return res;    }};


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国色天香综合网 | 欧美黄在线 | 国产一级桃视频播放 | 女人久久久www免费人成看片 | 在线免费小视频 | 欧美久久久久久久久 | 久色成人网 | 欧美视频99 | 亚洲国产精品一区二区三区 | 在线中文日韩 | 深夜福利视频绿巨人视频在线观看 | 亚洲精品com | 国产免费一区二区三区最新不卡 | 亚洲片在线观看 | 农村少妇吞精夜夜爽视频 | 久久久久久久国产视频 | 成人在线视频免费观看 | 精品亚洲午夜久久久久91 | 免费观看一区二区三区视频 | 亚洲综合精品 | 狠狠婷婷综合久久久久久妖精 | 成人毛片在线免费看 | 久久亚洲精品视频 | 国产精品久久久久久久不卡 | 久久久久久久久久一本门道91 | 法国性经典xxxhd | 黄色av免费网站 | 久久久久亚洲美女啪啪 | h视频在线观看免费 | 成人小视频在线播放 | 性生活视频一级 | 亚洲精品有限 | 久久精品国产清自在天天线 | 久久久aa | 久久久久久久久久美女 | av电影在线免费观看 | 日本高清com | 日韩视频在线免费 | 中国女人内谢8xxxxxx在 | 在线亚洲播放 | 毛片免费在线观看 |