当前位置:网站首页>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;
}
}
边栏推荐
- [Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
- How do you use lodash linking function- How do you chain functions using lodash?
- 【刷题篇】多数元素(超级水王问题)
- 树莓派如何连接WiFi
- Square root of X
- Redraw and reflow
- Arduino application development - LCD display GIF dynamic diagram
- Solve BP Chinese garbled code
- [set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
- Practical operation of vim
猜你喜欢

When writing a web project, SmartUpload is used for file upload and new string () is used for transcoding, but in the database, there will still be random codes similar to poker

跨境电商多商户系统怎么选

BMZCTF simple_ pop

Application of I2C protocol of STM32F103 (read and write EEPROM)
![[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN

Mutex and rwmutex in golang

解决bp中文乱码

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

JS realizes the animation effect of text and pictures in the visual area

Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
随机推荐
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
CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
Interface in TS
Practical operation of vim
vulnhub HA: Natraj
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
跨境电商多商户系统怎么选
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Database management tool, querious direct download
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
Deep dive kotlin synergy (20): build flow
【刷题篇】接雨水(一维)
Basic MySQL operations
JS realizes lazy loading of pictures
mysql字段userid逗号分开保存按userid查询
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
leetcode:297. 二叉树的序列化与反序列化
Social phobia of contemporary young people (III)
Two points -leetcode-540 A single element in an ordered array