当前位置:网站首页>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;
}
}
边栏推荐
- Attack and defense world misc advanced area can_ has_ stdio?
- 10 schemes to ensure interface data security
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { fmt.Pri
- Gnawing down the big bone - sorting (II)
- Attack and defense world misc advanced area Hong
- Mysql root 账号如何重置密码
- Postgresqlql advanced skills pivot table
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- SQL中MAX与GREATEST的区别
- 9 - class
猜你喜欢

攻防世界 MISC 进阶区 hong

Logo special training camp section II collocation relationship between words and graphics

Concurrent optimization summary
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency

安装人大金仓数据库

Advanced area of attack and defense world misc 3-11

LOGO特训营 第四节 字体设计的重要性

NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元

Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)

攻防世界 MISC 进阶区 Ditf
随机推荐
Google Earth Engine(GEE)——Tasks升级,实现RUN ALL可以一键下载任务类型中的所有影像
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
蓝队攻防演练中的三段作战
Sqlserver encrypts and decrypts data
【烹饪记录】--- 青椒炒千张
[the 2023 autumn recruitment of MIHA tour] open [the only exclusive internal push code of school recruitment eytuc]
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
特征缩放 标准化 归一化
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
攻防世界 MISC 進階區 Erik-Baleog-and-Olaf
LOGO特训营 第一节 鉴别Logo与Logo设计思路
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
集群的概述与定义,一看就会
LOGO特训营 第五节 字体结构与设计常用技法
Breakpoint debugging under vs2019 c release
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
SQL中MAX与GREATEST的区别
攻防世界 MISC 进阶区 can_has_stdio?
新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码