JAVA 3ms using DP


  • 0
    Y

    public class Solution {

    public int[] countBits(int num) {
        int[] dp=new int[num+1];
        int index1=0,index2=0;
        for(int i=1;i<=num;i++){
            if(index1==index2){
                index2=i;
                index1=0;
            }
            dp[i]=dp[index1++]+1;
        }
        return dp;
    }
    

    }


Log in to reply
 

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