Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 1.02 KB

0371-sum-of-two-integers.adoc

File metadata and controls

46 lines (27 loc) · 1.02 KB

371. Sum of Two Integers

这道题的关键有几点:

  1. 通过异或操作获取在不进位的情况下,各位的值;

  2. 通过相与加移位来来获取各个进位项;

  3. 重复上面的操作,直到进位项为 0 为止。

思考题:思考如何通过位运算来实现加减乘除?

参考资料

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example 1:

Input: a = 1, b = 2
Output: 3

Example 2:

Input: a = -2, b = 3
Output: 1
link:{sourcedir}/_0371_SumOfTwoIntegers.java[role=include]