Here is my solution


  • 0
    H
    public class Solution {
        public int[] countBits(int num) {
         int count=0;
         int[] res=new int[num+1];
         int t=0;
         for(int i=0;i<=num;i++)
         {
             int temp=i;
             for(int j=0;j<32;j++)
             {
                 if((temp & 1)!=0)
                    count++;
                temp=temp>>1;
             }  
            res[t]=count;
            t++;
            count=0;
         }
            return res;
        }
    }

Log in to reply
 

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