C++ easy-understanding


  • 2
    X
    class Solution {
    public:
        vector<int> countBits(int num) {
            vector<int> ans(num + 1, 0);
            for(int i = 1;i <= num; ++i){
                ans[i] = ans[i & (i - 1)] + 1;
            }
            return ans;
        }
    };

Log in to reply
 

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