Given two integers a
and b
, return the sum of the two integers without using the operators+
and-
Example 1:
Input: a = 1, b = 2
Output: 3
Example 2:
Input: a = 2, b = 3
Output: 5
Constraints:
1000 <= a, b <= 1000
給定兩個整數 a, b
要求不使用 + , - 運算來實作 兩數相加的演算法
對每個位元來說
相加分為兩個部份
下一個位元的進位可以透過 把對應位元做 & 然後再做 left shift
這個位元的合 可以發現除了因為不關心進位 所以是使用 XOR