给定一个非负整数 num。对于 0 ≤ i ≤ num 范围中的每个数字 i ,计算其二进制数中的 1 的数目并将它们作为数组返回。
示例1
输入
2
输出
[0,1,1]
加载中...
import java.util.*; public class Solution { /** * * @param num int整型 * @return int整型一维数组 */ public int[] countBits (int num) { // write code here } }
class Solution { public: /** * * @param num int整型 * @return int整型vector */ vector
countBits(int num) { // write code here } };
# # # @param num int整型 # @return int整型一维数组 # class Solution: def countBits(self , num ): # write code here
/** * * @param num int整型 * @return int整型一维数组 */ function countBits( num ) { // write code here } module.exports = { countBits : countBits };
# # # @param num int整型 # @return int整型一维数组 # class Solution: def countBits(self , num ): # write code here
2
[0,1,1]