338. Counting Bits
来源:互联网 发布:淘宝上能买到的黑科技 编辑:程序博客网 时间:2024/06/10 21:46
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.
Example:
For num = 5
you should return [0,1,1,2,1,2]
.
code:
class Solution(object):
def countBits(self, num):
"""
:type num: int
:rtype: List[int]
"""
res=[]
while num>=0:
res.append(bin(num).count('1'))
num-=1
return res[::-1]
阅读全文
0 0
- [leetcode] 338. Counting Bits
- 338. Counting Bits
- leetcode 338. Counting Bits
- LeetCodeOJ:338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode#338. Counting Bits
- 338. Counting Bits
- [LeetCode] 338. Counting Bits
- LeetCode 338. Counting Bits
- 338. Counting Bits
- [LeetCode]338. Counting Bits
- LeetCode-338. Counting Bits
- LeetCode *** 338. Counting Bits
- 338. Counting Bits
- (leetcode) 338. Counting Bits
- Swift 338. Counting Bits
- #leetcode#338. Counting Bits
- LeetCode 338. Counting Bits
- Halcon学习(四)图像处理中的两个坐标系
- 设屐师—创新捷径 小身材 大智慧
- maya单独显示线框和带贴图物体 优化视窗操作流畅度
- 深入浅出自动驾驶(一)-图像识别
- Recyclerview的一些个人理解与使用(六)Recyclerview的分段加载
- 338. Counting Bits
- 说说IO
- MySQL之索引学习笔记
- java学习 表达式集合输出
- ES6 yield使用
- UITableViewStyleGrouped 顶部空白
- java基础教程:运算符(8)
- 【LeetCode】4. Median of Two Sorted Arrays
- JAVA中for、while 以及do...while的比较