Created
January 10, 2022 21:38
-
-
Save makeapp007/039c1d16f985705df5e6ef03dbdb277c to your computer and use it in GitHub Desktop.
67. Add Binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def addBinary(self, a: str, b: str) -> str: | |
| m, n = int(a, 2), int(b, 2) | |
| while n: | |
| ans = m ^ n | |
| carry = (m & n) << 1 | |
| m = ans | |
| n = carry | |
| return bin(m)[2:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment