当前位置:网站首页>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;
}
}边栏推荐
- 3D reconstruction of point cloud
- TypeError: this. getOptions is not a function
- 二叉树递归套路总结
- February 13, 2022 -5- maximum depth of binary tree
- 2022.02.13 - SX10-30. Home raiding II
- Multi view 3D reconstruction
- [speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]
- Global and Chinese markets for welding products 2022-2028: Research Report on technology, participants, trends, market size and share
- Leecode learning notes
- Three.js-01 入门
猜你喜欢

【Note17】PECI(Platform Environment Control Interface)

One article deals with the microstructure and instructions of class

audiopolicy

数据库基础知识(面试)

February 13, 2022-4-symmetric binary tree

30 optimization skills about mysql, super practical

Hainan Nuanshen tea recruits warmhearted people: recruitment of the product experience recommender of Nuanshen multi bubble honey orchid single cluster

The difference between MVVM and MVC

Common JVM tools and optimization strategies

Expectation, variance and covariance
随机推荐
Arduino 测量交流电流
Expectation, variance and covariance
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
3 find the greatest common divisor and the least common multiple
Vcomp110.dll download -vcomp110 What if DLL is lost
Boring boring
Codeforces Global Round 19
Global and Chinese markets of tantalum heat exchangers 2022-2028: Research Report on technology, participants, trends, market size and share
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
Global and Chinese market of networked refrigerators 2022-2028: Research Report on technology, participants, trends, market size and share
Hcip day 12 (BGP black hole, anti ring, configuration)
终于搞懂什么是动态规划的
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
Activate function and its gradient
Function default parameters, function placeholder parameters, function overloading and precautions
d3dx9_ How to repair 31.dll_ d3dx9_ 31. Solution to missing DLL
Common model making instructions
Three.JS VR看房
Non rigid / flexible point cloud ICP registration
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)