40ms C solution


  • 1
    D
    int* countBits(int num, int* returnSize) {
        int* res = (int*)malloc(sizeof(int)*(num+1));
        *returnSize = num + 1;
        res[0]=0;
        for (int i=1;i<=num;i++) {
            if (i%2) res[i]=1+res[i-1];
            else res[i]=res[i/2];
        }
        return res;
    }

Log in to reply
 

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