알고리즘 공부
2020. 8. 20. 22:14
https://leetcode.com/problems/counting-bits/
/**
* @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;
};