当前位置:网站首页>Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
2022-07-04 22:45:00 【LuZhouShiLi】
The finger of the sword Offer 65. Do not add, subtract, multiply or divide
subject
Write a function , Find the sum of two integers , It is required that... Should not be used in the function body “+”、“-”、“*”、“/” Four operation symbols .
Ideas
Reference resources K God's solution :https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solution/mian-shi-ti-65-bu-yong-jia-jian-cheng-chu-zuo-ji-7/
- No carry sum is the same as XOR operation
- The law of carry and operation is the same ( Need to move one bit left )
Code
class Solution {
public int add(int a, int b) {
while(b != 0)
{
int c = (a & b) << 1;// c = carry
a ^= b;// Non carry and Exclusive or operation
b = c;// b = carry
}
return a;
}
}
边栏推荐
- Breakpoint debugging under vs2019 c release
- MD5 tool class
- 攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
- php短视频源码,点赞时会有大拇指动画飘起
- Introducing QA into the software development lifecycle is the best practice that engineers should follow
- 9 - class
- Practice and principle of PostgreSQL join
- The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
- The overview and definition of clusters can be seen at a glance
- Now MySQL cdc2.1 is parsing the datetime class with a value of 0000-00-00 00:00:00
猜你喜欢
PMO: compare the sample efficiency of 25 molecular optimization methods
Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
UML图记忆技巧
安装人大金仓数据库
Logo Camp d'entraînement section 3 techniques créatives initiales
2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri
将QA引入软件开发生命周期是工程师要遵循的最佳实践
Why is Dameng data called the "first share" of domestic databases?
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
Persistence mechanism of redis
随机推荐
MYSQL架构——逻辑架构
MD5 tool class
攻防世界 MISC 高手进阶区 001 normal_png
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Attack and defense world misc advanced area ditf
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
leetcode 72. Edit distance edit distance (medium)
The table is backed up in ODPs. Why check m in the metabase_ Table, the logical sizes of the two tables are inconsistent, but the number of
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
Domestic database chaos
达梦数据凭什么被称为国产数据库“第一股”?
Recommendation of mobile app for making barcode
不同环境相同配置项的内容如何diff差异?
【OpenGL】笔记二十九、抗锯齿(MSAA)
Embedded development: skills and tricks -- seven skills to improve the quality of embedded software code
Logo Camp d'entraînement section 3 techniques créatives initiales
Locust performance test - environment construction and use
Advanced area of attack and defense world misc 3-11
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
国产数据库乱象