Problem
|
|
Solution
Think this problem with an example.
Consider 15+9=24.
|
|
|
|
|
|
Thus, for any integer a
and b
, a + b = a^b + (a&b)<<1
. Because +
operator is not allowed, we can regard a^b
as new a
, and (a&b)<<1
as new b
. Repeat this until current carry is 0
.
The java implementation is like this:
|
|
Written with StackEdit.