LeetCode之Sum of Two Integers
发布日期:2021-06-29 14:08:15
浏览次数:2
分类:技术文章
本文共 534 字,大约阅读时间需要 1 分钟。
1、题目
Calculate the sum of two integers a and b, but you are not allowed to use the operator +
and -
.
Example:
Given a = 1 and b = 2, return 3.Credits:
Special thanks to for adding this problem and creating all test cases.to see which companies asked this question.
2、代码实现
public class Solution { public int getSum(int a, int b) { while(b != 0) { int tmp =(a & b) << 1; //a是每次相加,相当于和 a = a ^ b; //b相当于是进位 b = tmp; } return a; }}
转载地址:https://chenyu.blog.csdn.net/article/details/69661874 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年05月01日 15时10分07秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
利用MySQL进行数据复杂查询(2)
2019-04-29
MySQL 表与表之间的关系
2019-04-29
MySQL常见错误总结
2019-04-29
pymysql 的基础应用
2019-04-29
Python 管理程序改进——连接MYSQL
2019-04-29
Python 爬虫-豆瓣影星图片下载
2019-04-29
网页端数据库操作界面—主题函数文件
2019-04-29
网页端数据库操作界面-Html页面(1)
2019-04-29
Python爬虫 百度热搜热点
2019-04-29
excel的常用函数(二)
2019-04-29
excel文本函数
2019-04-29
电商大战二十年
2019-04-29
编程程软件测试思维方式:如何科学制定测试计划
2019-04-29
BLE蓝牙4.0串口调试助手
2019-04-29
树莓派WIFI设置
2019-04-29
nanopi2 启动信息
2019-04-29
phpstudy https
2019-04-29
Linux下EasyPanel版本安装及升级
2019-04-29