# （Leetcode）371. Sum of Two Integers

371. Sum of Two Integers
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.

## Solution

### 思路

“^” XOR operation, 获得(a+b)的“和”in each bit
“&” AND operation, 获得(a+b)的“进位”in each bit.

### Code

public class Solution {
public int getSum(int a, int b) {
if(b==0)
return a;
int sum = a^b;
int carrybit = (a&b)<<1;
return getSum(sum,carrybit);
}
}

#### [leetcode] 371. Sum of Two Integers 解题报告

2016-06-30 13:23:07

#### 371. Sum of Two Integers [easy] (Python)

2016-07-26 12:08:46

#### LeetCode - 371. Sum of Two Integers

2016-07-02 11:22:22

#### LeetCode 第 371 题 （Sum of Two Integers）

2016-07-01 19:56:30

#### 【leetcode】371. Sum of Two Integers【E】

2016-07-05 14:08:25

#### LeetCode--371. Sum of Two Integers（两个整数的和）Python

2018-01-16 15:41:54

#### leetcode 371. Sum of Two Integers(不用+ -实现加法）

2016-07-23 20:22:18

#### Leetcode 371. Sum of Two Integers 位运算实现加法 解题报告

2016-06-30 11:17:27

#### 371. Sum of Two Integers也许是最简洁易懂的做法了

2016-07-03 17:25:30

#### LeetCode算法(Python)--1、Two Sum

2017-03-02 10:08:10