当前位置:网站首页>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;
}
}

边栏推荐
- 金仓数据库KingbaseES 插件kdb_date_function
- MySQL field userid comma separated save by userid query
- 4 years of experience to interview test development, 10 minutes to end, ask too
- Kubernetes源码分析(一)
- GFS分布式文件系统(光是遇见已经很美好了)
- Introduction of pointer variables in function parameters
- [Thesis Writing] how to write the overall design of JSP tourism network
- FuncS sh file not found when using the benchmarksql tool to test kingbases
- Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
- [literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
猜你喜欢
![[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN](/img/7e/50fa6f65b5a4f0bb60909f57daff56.png)
[文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN

How to choose cross-border e-commerce multi merchant system

Integration of Android high-frequency interview questions (including reference answers)

GFS分布式文件系统(光是遇见已经很美好了)

Database management tool, querious direct download

P35-P41 fourth_ context

Preliminary cognition of C language pointer
![[free completion] development of course guidance platform (source code +lunwen)](/img/14/7c1c822bda050a805fa7fc25b802a4.jpg)
[free completion] development of course guidance platform (source code +lunwen)

Fcpx template: sweet memory electronic photo album photo display animation beautiful memory

Two points -leetcode-540 A single element in an ordered array
随机推荐
[fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
MC Layer Target
[nlp] - brief introduction to the latest work of spark neural network
data2vec! New milestone of unified mode
Hj35 serpentine matrix
2022-02-14 (394. String decoding)
xrandr修改分辨率與刷新率
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
[set theory] binary relation (example of binary relation on a | binary relation on a)
Prefix and (continuously updated)
Php+mysql registration landing page development complete code
Basic types of data in TS
[dynamic programming] subsequence problem
Classes in TS
Matplotlib -- save graph
因子选股-打分模型
Dive into deep learning - 2.1 data operation & Exercise
Xrandr modify resolution and refresh rate
Integration of Android high-frequency interview questions (including reference answers)
Design and implementation of JSP logistics center storage information management system