当前位置:网站首页>Leetcode sword finger offer brush questions - day 21
Leetcode sword finger offer brush questions - day 21
2022-07-05 23:05:00 【DEGv587】
Leetcode The finger of the sword Offer How to brush questions :
The finger of the sword Offer 15. Binary 1 The number of
solution : An operation
public class Solution {
public int hammingWeight(int n) {
int ret = 0;
while (n != 0) {
ret += n & 1;
n >>>= 1;
}
return ret;
}
}public class Solution {
public int hammingWeight(int n) {
int ret = 0;
while (n != 0) {
ret++;
n &= (n - 1);
}
return ret;
}
}The finger of the sword Offer 65. Do not add, subtract, multiply or divide
solution : An operation
Non carry and :a ^ b
Carry sum :(a & b) << 1
and : Carry sum + Non carry and = (a ^ b) + ((a & b) << 1)
loop , When carry is 0 Exit from time
class Solution {
public int add(int a, int b) {
while (b != 0) {
int c = (a & b) << 1;// Carry sum
a ^= b;// Non carry and
b = c;// take c Assign a value to b, here b Is carry and
}
return a;
}
}边栏推荐
- LeetCode145. Post order traversal of binary tree (three methods of recursion and iteration)
- VOT toolkit environment configuration and use
- 判斷二叉樹是否為完全二叉樹
- First, redis summarizes the installation types
- [secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]
- Go语言实现原理——Map实现原理
- LeetCode102. Sequence traversal of binary tree (output by layer and unified output)
- Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
- [speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
- The method and principle of viewing the last modification time of the web page
猜你喜欢

Spectrum analysis of ADC sampling sequence based on stm32

The difference between MVVM and MVC

两数之和、三数之和(排序+双指针)

Codeforces Global Round 19

Unity Max and min constraint adjustment

Non rigid / flexible point cloud ICP registration

Three. JS VR house viewing

Week 17 homework

Masked Autoencoders Are Scalable Vision Learners (MAE)

Use of grpc interceptor
随机推荐
My experience and summary of the new Zhongtai model
Element positioning of Web Automation
I closed the open source project alinesno cloud service
14种神笔记方法,只需选择1招,让你的学习和工作效率提高100倍!
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
Registration and skills of hoisting machinery command examination in 2022
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
3 find the greatest common divisor and the least common multiple
Douban scoring applet Part-2
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
TCC of distributed solutions
Shell: operator
Three. JS VR house viewing
Nangou Gili hard Kai font TTF Download with installation tutorial
【Note17】PECI(Platform Environment Control Interface)
Alibaba Tianchi SQL training camp task4 learning notes
leecode-学习笔记
并查集实践
Three.JS VR看房
fibonacci search