Topic:
Given two integers a and B, it is required not to use ' + ' and '-' to return the and of the two integers.
Ideas for solving problems:
Because the subtraction symbol cannot be used, it is considered that the bitwise-and-bitwise-OR-bitwise operation of the binary number is known to be a^b or can be obtained without taking into account the result of the rounding, bitwise and a&b of the case where the rounding can be obtained. So the result can be obtained by adding the results of the rounding to the left one and then the result of the addition of the different or. The rounding result, when added to the XOR or result, may also produce a carry. Therefore, loop the above steps until the result of the carry is terminated at 0 o'clock.
Code (Python):
Class Solution (object):
def getsum (self, A, b): ""
: Type a:int
: Type b:int
: Rtype:int
"" C6/>while b!= 0:
carry = a & B =
(a ^ b)
B = (carry << 1) return
A If a <= 0x7fffffff els E a| (~0x100000000+1)