[LeetCode]371.Sum of Two Integers两数相加
2017-05-09 12:58
417 查看
371.
Calculate the sum of two integers a and b,
but you are not allowed to
use the operator
两数相加,不使用加减符号。
使用异或、与、位移运算符。
Calculate the sum of two integers a and b,
but you are not allowed to
use the operator
+and
-.
两数相加,不使用加减符号。
使用异或、与、位移运算符。
class Solution { public: int getSum(int a, int b) { if (b == 0) return a; else { int sum = a^b; int temp = (a&b) << 1; return (getSum(sum, temp)); } } };
相关文章推荐
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- LeetCode 371. Sum of Two Integers (两数之和)
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- 链表:链表两数相加( LeetCode 2. Add Two Numbers(两数相加))
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- [LeetCode] Add Two Numbers 两数相加
- [LeetCode] Sum of Two Integers 两数之和
- LeetCode Divide Two Integers 不使用除号取模乘号实现两数相除
- [LeetCode] Divide Two Integers 两数相除
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- leetcode 371.Sum of Two Integers
- LeetCode 2. Add Two Numbers(两数相加)
- [LeetCode] 29. Divide Two Integers 两数相除
- [Leetcode] divide two integers 两数相除
- [LeetCode] 2. Add Two Numbers 两数相加 @python
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- LeetCode 2.Add Two Numbers,67.Add Binary,371.Sum of Two Integers,66.Plus One
- 【LeetCode】- Two Sum(两数相加)
- LeetCode 371.Sum of Two Integers 解题报告
- [LeetCode] 371.Sum of Two Integers