-
Method 1: Dynamic Programming
i
run from0
tonum
. So when calculating results[i], we have known results[i >> 1]. The difficult of number of 1's is only decided by last bit of results[i].results[i] = results[i >> 1] + (i as i32 & 1);
-
Method 2: call function
i32.count_ones()
-
方法1:动态规划
i
从0
运行到num
。所以计算results[i]时,我们已经知道results[i >> 1]。1's的个数差只由results[i]最后一个比特决定。results[i] = results[i >> 1] + (i as i32 & 1);
-
方法2:调用函数
i32.count_ones()