[LeetCode]#371. Sum of Two Integers

Input: a = 1, b = 2
Output: 3
Input: a = -2, b = 3
Output: 1
class Solution:
def getSum(self, a, b):
mask = 0xffffffff
sum = (a ^ b) & mask
carry = a & b
while carry!=0:
a = sum
b = (carry << 1) & mask
sum = (a ^ b) & mask
carry = a & b
if sum & 0x80000000:
sum -= 0x100000000
return sum

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a hash cracking tool using Python

Ready Magento Certifycation

The Pythonic Way

Time Complexities By Insertion Sort , Merge Sort And Quick Sorts

Why are most companies using cloud computing? ☁️

With something like that you can save

Deep dive into AWS for developers | Part2

Non-Blocking Java — Beyond the Hype

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

13. Roman to Integer

Use of python dictionary get function

Two Sum | Interview Question

[LeetCode]#2119. A Number After a Double Reversal