3ms Java DP Solution


  • 0
    G
    public class Solution {
        public int[] countBits(int num) {
            int[] ret=new int[num+1];
            ret[0]=0;
            int j=0;
            for(int i=1;i<=num;i++){
                
                if((i & (i-1)) == 0)j=0;
                ret[i]=1+ret[j];
                j++;
            }
            return ret;
        }
    }

Log in to reply
 

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