O(n) time dp solution c++


  • 0
    K
    vector<int> countBits(int num) {
            std::vector<int> a(num+1,0);
            
            if(num==0) return a;
            
            for(int i=1;i<=num;++i){
                a[i]=a[i/2]+i%2;
            }
            
            return a;
        }
    

Log in to reply
 

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