short answer of c++ using loop copy


  • 0
    W

    vector<int> countBits(int num) {
    vector<int> result;
    int j=0,p=1,i=1;
    result.push_back(0);
    while(i<=num)
    {
    j=0;
    while(j<p&&i<=num)
    {
    result.push_back(result[j]+1);
    j++;
    i++;
    }
    p=p*2;
    }
    return result;
    }


Log in to reply
 

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