LeetCode之Sum of Two Integers
来源:互联网 发布:怎么屏蔽网络监控 编辑:程序博客网 时间:2024/05/17 05:52
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 @fujiaozhu for adding this problem and creating all test cases.
Subscribe 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; }}
0 0
- LeetCode之Sum of Two Integers
- 【Leetcode】Sum of Two Integers
- leetcode Sum of Two Integers
- LeetCode---Sum of Two Integers
- LeetCode:Sum of Two Integers
- LeetCode:Sum of Two Integers
- LeetCode Sum of Two Integers
- Leetcode Sum of Two Integers
- #leetcode#Sum of Two Integers
- Leetcode-Sum of Two Integers
- leetcode--sum of two integers
- [Leetcode] Sum of Two Integers
- LeetCode|Sum of Two Integers
- [Leetcode] Sum of Two Integers
- LEETCODE--Sum of Two Integers
- LeetCode:Sum of Two Integers
- LeetCode Sum of Two Integers
- leetcode[Sum of Two Integers]
- Win10下Android开发环境搭建
- Atitit 提升进度的大原则与方法 高层方法 attilax总结
- [python3]nba球员数据爬虫
- 【Python】多进程
- 浏览器标准模式和怪异模式
- LeetCode之Sum of Two Integers
- wdcp面板升级PHP7.0脚本
- 类欧几里得算法与推导
- Effective STL: 选择合适的容器
- JS画线
- Centos7中进程操作
- Atitit 手机图片备份解决方案attilax总结
- 模拟赛 红蓝牌
- 浅谈在chrome中“google search”与“输入URL”的区别