代码nullgray code

最近使用开发的过程中出现了一个小问题,顺便记录一下原因和方法--代码null

    标题:

    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 - 0
01 - 1
11 - 3
10 - 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.

    代码如下:

    vector<int> grayCode(int n) {
        vector<int> result;
        int m=1<<n;
        for(int i=0;i<m;i++)
        {
            result.push_back(i^(i>>1));
        }
        return result;
    }

文章结束给大家分享下程序员的一些笑话语录: Borland说我很有前途,Sun笑了;Sun说我很有钱,IBM笑了;IBM说我很专业,Sybase笑了;Sybase说我数据库很牛,Oracle笑了;Oracle说我是开放的,Linux笑了;Linux说我要打败Unix,微软笑了;微软说我的系统很稳定,我们都笑了。

--------------------------------- 原创文章 By
代码和null
---------------------------------

posted @ 2013-05-28 23:00  坚固66  阅读(159)  评论(0编辑  收藏  举报