LeetCode 338
来源:互联网 发布:python怎么取最大 编辑:程序博客网 时间:2024/05/01 15:10
338. Counting Bits
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]
.
思路 递归的分区 [2-3] [4-7] [7-15]等
public class Solution { public int[] countBits(int num) { int[] result = new int[num+1]; for(int i = 0;i <= num;i++){ result[i] = get(i); } return result; } public int get(int num){ if(num == 0){ return 0; }else if(num == 1){ return 1; }else{ return 1 + get(num - max(num)); } } public int max(int num){ int count = 0; while(num != 1){ num /= 2; count++; } return (int) Math.pow(2,count); }}
0 0
- LEETCODE 338
- leetcode 338
- LeetCode 338
- LeetCode 338
- 【LeetCode-338】Counting Bits
- leetcode-338-Counting Bits
- Leetcode 338 Counting Bits
- LeetCode 338 :Counting Bits
- [leetcode-338]Counting Bits
- 【LeetCode-338】 Counting Bits
- LeetCode 338 Counting Bits
- Counting Bits leetcode 338
- [LeetCode 338] Counting Bits
- LeetCode-338:Counting Bits
- Leetcode no. 338
- LeetCode-338:Counting Bits
- LeetCode[338] Counting Bits
- LeetCode#338 Counting Bits
- neo4j-ogm-core使用小记
- JS的节点操作:创建、增加、删除、复制、查找
- 002一番寻找后,终于找到简单好用的利用runtime解决数组字典为nil时造成的程序崩溃的第三方
- VideoView
- 一个对含中文字符串在内的字符串排序简便方法
- LeetCode 338
- linux系统的简述和优势,趋势所在!!
- BZOJ1880: [Sdoi2009]Elaxia的路线
- ROS里面的几个python写的工具
- 你中招了吗?加密勒索软件攻击趋势分析
- BZOJ1133: [POI2009]Kon
- strcpy_s,sprintf_s,wcscpy_s,swprintf_s,wcscat_s,加了_s就真的安全吗?
- 计算机--机器学习---机器learning技法sum
- libevent学习之跨平台Reactor接口的实现