#371
Sum of Two Integers
medium· Bit Manipulationruns: 0Given two integers a and b, return the sum of the two integers without using the operators + or -.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 235
class Solution:
def getSum(self, a: int, b: int) -> int:
mask = 0xFFFFFFFF
while (b & mask) != 0:
carry = (a & b) << 1
a = a ^ b
b = carry
return a & mask if b > 0 else a
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.