当前位置:网站首页>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;
}
}
边栏推荐
- openresty ngx_lua正則錶達式
- Methods modified by static
- Hcip day 12 (BGP black hole, anti ring, configuration)
- Masked Autoencoders Are Scalable Vision Learners (MAE)
- 3D reconstruction of point cloud
- Ieventsystemhandler event interface
- The method and principle of viewing the last modification time of the web page
- 派对的最大快乐值
- Yiwen gets rid of the garbage collector
- Selenium+pytest automated test framework practice
猜你喜欢
2022 R2 mobile pressure vessel filling review simulation examination and R2 mobile pressure vessel filling examination questions
Paddy serving v0.9.0 heavy release multi machine multi card distributed reasoning framework
MoCo: Momentum Contrast for Unsupervised Visual Representation Learning
第十七周作业
Realize reverse proxy client IP transparent transmission
Masked Autoencoders Are Scalable Vision Learners (MAE)
Debian 10 installation configuration
Alibaba Tianchi SQL training camp task4 learning notes
openresty ngx_ Lua request response
CorelDRAW plug-in -- GMS plug-in development -- new project -- macro recording -- VBA editing -- debugging skills -- CDR plug-in (2)
随机推荐
openresty ngx_lua请求响应
Detailed explanation of pointer and array written test of C language
Event trigger requirements of the function called by the event trigger
CJ mccullem autograph: to dear Portland
Selenium+Pytest自动化测试框架实战
Data type, variable declaration, global variable and i/o mapping of PLC programming basis (CoDeSys)
Element operation and element waiting in Web Automation
Nacos 的安装与服务的注册
Use of metadata in golang grpc
LeetCode145. Post order traversal of binary tree (three methods of recursion and iteration)
Simple and beautiful method of PPT color matching
Getting started stm32--gpio (running lantern) (nanny level)
Openresty ngx Lua regular expression
Codeforces Global Round 19
Registration and skills of hoisting machinery command examination in 2022
leecode-学习笔记
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
The method and principle of viewing the last modification time of the web page
Composition of interface