当前位置:网站首页>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;
}
}
边栏推荐
- ZIP文件的导出
- [untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
- The latest activation free version of Omni toolbox
- "Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
- The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
- Taking two column waterfall flow as an example, how should we build an array of each column
- 重绘和回流
- 因果AI,下一代可信AI的产业升级新范式?
- What's wrong with SD card data damage? How to recover SD card data damage
- Introduction to eth
猜你喜欢
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
第十届中国云计算大会·中国站:展望未来十年科技走向
[graduation season · aggressive technology Er] Confessions of workers
[brush questions] find the number pair distance with the smallest K
[nlp] - brief introduction to the latest work of spark neural network
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
竞品分析撰写
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
JS native common knowledge
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
随机推荐
CVPR 2022 | Dalian Technology propose un cadre d'éclairage auto - étalonné pour l'amélioration de l'image de faible luminosité de la scène réelle
Mongodb slow query optimization analysis strategy
Appium automated testing framework
Interaction free shell programming
[fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
How do you use lodash linking function- How do you chain functions using lodash?
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
Taking two column waterfall flow as an example, how should we build an array of each column
毕设-基于SSM宠物领养中心
Sklearn data preprocessing
The longest subarray length with a positive product of 1567 recorded by leecode
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
How to connect WiFi with raspberry pie
Deep dive kotlin synergy (19): flow overview
2.14 simulation summary
Basic types of data in TS
【刷题篇】多数元素(超级水王问题)
[home push IMessage] software installation virtual host rental tothebuddy delay
Application of I2C protocol of STM32F103 (read and write EEPROM)
MPLS setup experiment