LeetCode题目:Gray Code

原题地址:https://leetcode.com/problems/gray-code/

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

        return coll;
    }
};

 

posted @ 2016-03-03 17:40  Runnyu  阅读(165)  评论(0编辑  收藏  举报