leetcode-371. Sum of Two Integers
来源:互联网 发布:linux 守护进程启动 编辑:程序博客网 时间:2024/06/05 00:46
1、来源:点击打开链接
2、题目:
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.
3、代码(主要还是参考了这里点击打开链接):
class Solution {public: int getSum(int a, int b) { int c,d; c=a^b; d=a&b; return d==0?c:(getSum(c,(d<<1))); }};
010000110111
原理2:
如果a,b相加没有进位,则a^b即为a+b;
若是有进位,则可以使用a^b,与(a&b)<<1相加即可
5、加油啦~~写一点点博客也好,也要坚持下呢,小hao同学加油~
0 0
- LeetCode 371. Sum of Two Integers
- 371. Sum of Two Integers LeetCode OJ
- [Leetcode]371. Sum of Two Integers
- LeetCode - 371. Sum of Two Integers
- <LeetCode OJ> 371. Sum of Two Integers
- LeetCode 371. Sum of Two Integers
- leetcode 371. Sum of Two Integers
- leetcode 371.Sum of Two Integers
- LeetCode 371. Sum of Two Integers
- 371. Sum of Two Integers(Leetcode)
- leetcode 371. Sum of Two Integers
- 【leetcode】371. Sum of Two Integers【E】
- [leetcode] 371. Sum of Two Integers
- leetcode.371. Sum of Two Integers
- 371. Sum of Two Integers--LeetCode Record
- LeetCode—371. Sum of Two Integers
- Leetcode 371. Sum of Two Integers
- LeetCode 371. Sum of Two Integers
- 启动tomcat报错 java.lang.Exception: Socket bind failed
- Retrofit2.0使用
- [C++]高效使用迭代器的一些建议
- java解析xml文件
- coolweather Debug
- leetcode-371. Sum of Two Integers
- scala基础6-lazy 懒执行特性
- BMP图像的处理(24位转16位)
- hibernate缓存机制
- LeetCode--No.144--Binary Tree Preorder Traversal
- 两个栈实现一个队列,两个队列实现一个栈
- 表达式树(公共表达式消除 uva 12219)
- Python读取文件
- Android获取屏幕宽高