Easy to understand, C#, DP


  • 0
    P
     public int[] CountBits(int num) {
            int[] result = new int[num+1];
            result[0]=0;
            for(int i=1;i<=num;i++)
            {
                int tmp=(i&(i-1));
                result[i]=result[tmp]+1;
            }
            return result;
        }
    

Log in to reply
 

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