Files
LeetCode-Go/leetcode/0371.Sum-of-Two-Integers/371. Sum of Two Integers.go
2020-08-07 17:06:53 +08:00

14 lines
214 B
Go

package leetcode
func getSum(a int, b int) int {
if a == 0 {
return b
}
if b == 0 {
return a
}
// (a & b)<<1 计算的是进位
// a ^ b 计算的是不带进位的加法
return getSum((a&b)<<1, a^b)
}