当前位置:网站首页>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;
}
}
边栏推荐
- 实现反向代理客户端IP透传
- Go语言实现原理——Map实现原理
- 6-axis and 9-axis IMU attitude estimation
- Marginal probability and conditional probability
- Non rigid / flexible point cloud ICP registration
- 视频标准二三事
- Distributed solution selection
- 利用LNMP实现wordpress站点搭建
- Leetcode weekly The 280 game of the week is still difficult for the special game of the week's beauty team ~ simple simulation + hash parity count + sorting simulation traversal
- [speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]
猜你喜欢
Ieventsystemhandler event interface
Finally understand what dynamic planning is
CJ mccullem autograph: to dear Portland
【Note17】PECI(Platform Environment Control Interface)
Go语言实现原理——Map实现原理
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
Overview of Fourier analysis
Fix the memory structure of JVM in one article
Starting from 1.5, build a micro Service Framework -- log tracking traceid
[digital signal denoising] improved wavelet modulus maxima digital signal denoising based on MATLAB [including Matlab source code 1710]
随机推荐
Arduino measures AC current
3D reconstruction of point cloud
LeetCode102. Sequence traversal of binary tree (output by layer and unified output)
一文搞定class的微觀結構和指令
Simple and beautiful method of PPT color matching
Nacos 的安装与服务的注册
一文搞定JVM常见工具和优化策略
Matlab smooth curve connection scatter diagram
Masked Autoencoders Are Scalable Vision Learners (MAE)
终于搞懂什么是动态规划的
C Primer Plus Chapter 9 question 9 POW function
关于MySQL的30条优化技巧,超实用
openresty ngx_ Lua regular expression
Ultrasonic sensor flash | LEGO eV3 Teaching
第十七周作业
Go语言实现原理——Map实现原理
Vision Transformer (ViT)
Commonly used probability distributions: Bernoulli distribution, binomial distribution, polynomial distribution, Gaussian distribution, exponential distribution, Laplace distribution and Dirac delta d
Distributed solution selection
Un article traite de la microstructure et des instructions de la classe