Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 1.07 KB

371-sum-of-two-integers.md

File metadata and controls

45 lines (29 loc) · 1.07 KB

371. Sum of Two Integers - 两整数之和

不使用运算符 + 和 - ​​​​​​​,计算两整数 ​​​​​​​a 、b ​​​​​​​之和。

示例 1:

输入: a = 1, b = 2
输出: 3

示例 2:

输入: a = -2, b = 3
输出: 1

题目标签:Bit Manipulation

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
cpp 0 ms 835.6 KB
class Solution {
public:
    int getSum(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return getSum(a ^ b, (a & b) << 1);
        }
    }
};