当前位置:网站首页>Number of 1 in binary (simple difficulty)
Number of 1 in binary (simple difficulty)
2022-07-03 04:31:00 【Nulibiao】
Title Overview ( Medium difficulty )

Topic link :
Point me into the leetcode
Ideas and code
Train of thought display
The idea of this topic is still taken from us K God boss , I won't go into too much detail here
About logical shift right , Move left , If you are not clear about the right shift, you can see this solution :
Click to enter the solution
Or take a look at my blog :
Click me to enter the blog
Students who can't do binary subtraction can see this blog :
Click me to enter the blog
Code example
Code 1:
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res = 0;
while(n != 0) {
res += n&1;
// Logical shift right
n >>>= 1;
}
return res;
}
}

Code 2:
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res = 0;
while(n != 0) {
n &= (n-1);
res++;
}
return res;
}
}

边栏推荐
- 多板块轮动策略编写技巧----策略编写学习教材
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- [software testing-6] & Test Management
- What's wrong with SD card data damage? How to recover SD card data damage
- [pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
- vulnhub HA: Natraj
- Youdao cloud notes
- [set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
- Function introduction of member points mall system
- [set theory] binary relation (example of binary relation on a | binary relation on a)
猜你喜欢
![[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius](/img/01/c118725f74e39742df021b5dbcc33b.jpg)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius

Redis persistence principle

FFMpeg filter

使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭

The latest activation free version of Omni toolbox

GFS distributed file system (it's nice to meet it alone)

After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me

Integration of Android high-frequency interview questions (including reference answers)
![[fxcg] market analysis today](/img/ac/294368e3496a5b808b38833053ee81.jpg)
[fxcg] market analysis today

金仓KFS数据双向同步场景部署
随机推荐
Mongodb slow query optimization analysis strategy
消息队列(MQ)介绍
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
[NLP]—sparse neural network最新工作简述
Kubernetes源码分析(一)
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
GFS distributed file system (it's nice to meet it alone)
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
Mount NFS in kubesphere
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
2022 new examination questions for the main principals of hazardous chemical business units and examination skills for the main principals of hazardous chemical business units
Asp access teaching management system design finished product
C language series - Section 3 - functions
IPhone x forgot the boot password
Bugku CTF daily question baby_ flag. txt
xrandr修改分辨率與刷新率
Some information about the developer environment in Chengdu
Wine travel Jianghu War: Ctrip is strong, meituan is strong, and Tiktok is fighting
vulnhub HA: Natraj