What's the problem of my code?


  • 0
    S

    public class Solution {
    public int[] countBits(int num) {
    int a[] = new int[num + 1];
    int powder = 0;
    for(int i = 0; i < num + 1 ; i++) {
    if(i == 0)
    a[i] = 0;
    if(1 << powder == i) {
    powder ++;
    a[i] = 1;
    }
    else if(i < 1 << (powder + 1) && i > 1 << powder) {
    a[i] = a[i - 1 << powder + 1] + 1;
    }
    }
    return a;
    }
    }


Log in to reply
 

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