当前位置:网站首页>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;
}
}边栏推荐
- Starting from 1.5, build a micro Service Framework -- log tracking traceid
- [speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]
- TOPSIS code part of good and bad solution distance method
- Global and Chinese market of water treatment technology 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for children's amusement facilities 2022-2028: Research Report on technology, participants, trends, market size and share
- 媒体查询:引入资源
- Arduino 测量交流电流
- Go语言实现原理——Map实现原理
- Three.js-01 入门
- Three.JS VR看房
猜你喜欢

Masked Autoencoders Are Scalable Vision Learners (MAE)
![[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]](/img/03/8fa104b177698a15b7ffa70d4fb524.jpg)
[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]

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

Getting started stm32--gpio (running lantern) (nanny level)

Fix the memory structure of JVM in one article

audiopolicy

实现反向代理客户端IP透传

Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~

Douban scoring applet Part-2

Basic knowledge of database (interview)
随机推荐
3 find the greatest common divisor and the least common multiple
基于STM32的ADC采样序列频谱分析
【Note17】PECI(Platform Environment Control Interface)
Overview of Fourier analysis
Starting from 1.5, build a micro Service Framework -- log tracking traceid
One article deals with the microstructure and instructions of class
The maximum happiness of the party
Leetcode buys and sells stocks
Global and Chinese market of networked refrigerators 2022-2028: Research Report on technology, participants, trends, market size and share
Southeast Asia e-commerce guide, how do sellers layout the Southeast Asia market?
Global and Chinese markets for welding products 2022-2028: Research Report on technology, participants, trends, market size and share
Roman numeral to integer
openresty ngx_ Lua request response
实现反向代理客户端IP透传
My experience and summary of the new Zhongtai model
Krypton Factor-紫书第七章暴力求解
openresty ngx_lua请求响应
判斷二叉樹是否為完全二叉樹
Sum of two numbers, sum of three numbers (sort + double pointer)
Hcip day 12 (BGP black hole, anti ring, configuration)