当前位置:网站首页>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;
}
}
边栏推荐
- Create Ca and issue certificate through go language
- LOGO特訓營 第三節 首字母創意手法
- 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
- 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
- Business is too busy. Is there really no reason to have time for automation?
- Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集
- POM in idea XML dependency cannot be imported
- Li Kou 98: verify binary search tree
猜你喜欢

Attack and Defense World MISC Advanced Area Erik baleog and Olaf

Google Earth Engine(GEE)——基于 MCD64A1 的 GlobFire 日常火灾数据集

10 schemes to ensure interface data security

NFT Insider #64:电商巨头eBay提交NFT相关商标申请,毕马威将在Web3和元宇宙中投入3000万美元
[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

Redis的持久化机制

攻防世界 MISC 进阶区 can_has_stdio?

UML图记忆技巧

LOGO特训营 第二节 文字与图形的搭配关系
随机推荐
Apachecn translation, proofreading, note sorting activity progress announcement 2022.7
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
攻防世界 MISC 高手进阶区 001 normal_png
国产数据库乱象
Easy to use app recommendation: scan QR code, scan barcode and view history
PostgreSQLSQL高级技巧透视表
虚拟人产业面临的挑战
质量体系建设之路的分分合合
Attack and defense world misc advanced grace-50
【室友用一局王者荣耀的时间学会了用BI报表数据处理】
La prospérité est épuisée, les choses sont bonnes et mauvaises: Où puis - je aller pour un chef de station personnel?
Recommendation of mobile app for making barcode
Concurrent network modular reading notes transfer
MYSQL架构——用户权限与管理
剑指 Offer 67. 把字符串转换成整数
Close system call analysis - Performance Optimization
攻防世界 MISC 进阶区 can_has_stdio?
Logo special training camp section III initial creative techniques
Attack and defense world misc master advanced zone 001 normal_ png
阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”