Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def addBinary(self, a: str, b: str) -> str:
- # first convert to numbers
- x = int(a, 2)
- y = int(b, 2)
- while y:
- answer_without_carry = x^y # yaad karo
- carry = (x&y) << 1 # AND operator and left shift
- # now you need to keep doing untill there is no carry left
- x, y = answer_without_carry, carry
- return bin(x)[2:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement