RUNTIME Error,But run well mo my mac with gcc compiler.


  • 0
    J
    class Solution {
    

    public:
    vector<int> grayCode(int n){
    vector<int> re;
    if(n == 1) //如果为1,则返回两个值的vector
    {
    vector<int> re;
    re.push_back(0);
    re.push_back(1);
    return re;
    }
    else
    {

        vector<int> re1 = grayCode(n-1);      //否则进行递归求解,返回n-1的格雷码,再加上前面的全零或者全一;
        for(vector<int>::iterator ite = re1.begin(); ite != re1.end(); ite++)
        {
            re.push_back(*ite);
        }
        for(vector<int>::iterator ite = re1.end() - 1; ite >= re1.begin(); ite--)
        {
            int j = pow(2,n-1);
            re.push_back(*ite + j);
        }
    }
    return re;
    

    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.