알고리즘 공부 2020. 8. 20. 22:14

https://leetcode.com/problems/counting-bits/

 

Counting Bits - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

/**
 * @param {number} num
 * @return {number[]}
 */
var countBits = function(num) {    
    const result = [];
    for( let i=0; i<=num; ++i )
    {
        if( i<2 )
            result.push(i);
        else
            result.push( result[Math.floor(i/2)] + i%2 );
    }
    return result;
};
posted by Sense.J
: