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

边栏推荐
- A outsourcing boy's mid-2022 summary
- Bugku CTF daily question baby_ flag. txt
- When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
- Priv-app permission异常
- 重绘和回流
- JVM原理简介
- Employee attendance management system based on SSM
- Introduction of pointer variables in function parameters
- FFMpeg example
- sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
猜你喜欢
![[nlp] - brief introduction to the latest work of spark neural network](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[nlp] - brief introduction to the latest work of spark neural network

Golang -- realize file transfer

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

使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found

Why should programmers learn microservice architecture if they want to enter a large factory?
![[NLP]—sparse neural network最新工作简述](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[NLP]—sparse neural network最新工作简述

C language series - Section 3 - functions

2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank

Joint set search: merge intervals and ask whether two numbers are in the same set

Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
随机推荐
[nlp] - brief introduction to the latest work of spark neural network
220214c language learning diary
2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
[free completion] development of course guidance platform (source code +lunwen)
stm32逆向入门
What's wrong with SD card data damage? How to recover SD card data damage
Mount NFS in kubesphere
金仓数据库KingbaseES 插件kdb_database_link
消息队列(MQ)介绍
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
RSRS index timing and large and small disc rotation
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
How do you use lodash linking function- How do you chain functions using lodash?
Web - Information Collection
[fxcg] market analysis today
Two drawing interfaces - 1 Matlab style interface
2022-02-13 (347. Top k high frequency elements)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius
Auman Galaxy new year of the tiger appreciation meeting was held in Beijing - won the double certification of "intelligent safety" and "efficient performance" of China Automotive Research Institute
[set theory] binary relation (example of binary relation on a | binary relation on a)