3 lines c++ solution


  • 0
    vector<int> countBits(int num) {
            vector<int> res(num+1,0);
            for(int i = 0; i<=num; i++)res[i] =  (i&1==1) + res[i>>1];
            return res;
    }
    

Log in to reply
 

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