当前位置:网站首页>2022-02-12 (338. Bit count)
2022-02-12 (338. Bit count)
2022-07-03 04:18:00 【TickTick123】
class Solution {
public int[] countBits(int n) {
int[] result=new int[n+1];
for(int i=0;i<=n;++i){
result[i]=oneCount(i);
}
return result;
}
public int oneCount(int x){
int count=0;
while(x!=0){
x=x&(x-1);
++count;
}
return count;
}
}
Dynamic programming :
class Solution {
public int[] countBits(int n) {
int[] result=new int[n+1];
for(int i=1;i<=n;++i){
result[i]=result[i&(i-1)]+1;
}
return result;
}
}
边栏推荐
- Idea shortcut keys
- Practical operation of vim
- Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
- 使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found
- Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
- eth入门之简介
- x Problem B
- [nlp] - brief introduction to the latest work of spark neural network
- [set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
- mysql字段userid逗号分开保存按userid查询
猜你喜欢

Data Lake three swordsmen -- comparative analysis of delta, Hudi and iceberg

BMZCTF simple_ pop

JS native common knowledge

Busycal latest Chinese version

【刷题篇】 找出第 K 小的数对距离

Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness

国产PC系统完成闭环,替代美国软硬件体系的时刻已经到来

Appium自动化测试框架

JS realizes lazy loading of pictures

Mutex and rwmutex in golang
随机推荐
redis 持久化原理
[no title] 2022 chlorination process examination content and free chlorination process examination questions
Idea shortcut keys
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
Competitive product analysis and writing
vim 的实用操作
540. Single element in ordered array
第十届中国云计算大会·中国站:展望未来十年科技走向
DAPP for getting started with eth
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Social phobia of contemporary young people (III)
Classes in TS
[fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
[set theory] inclusion exclusion principle (including examples of exclusion principle)
Solve BP Chinese garbled code
leetcode:297. Serialization and deserialization of binary tree
MySQL create table
The latest activation free version of Omni toolbox