67-Add-Binary
Sat 17 May 2025
https://leetcode.com/problems/add-binary
import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
def addBinary(self, a: str, b: str) -> str:
s = []
carry = 0
i = len(a) - 1
j = len(b) - 1
while i >= 0 or j >= 0 or carry:
if i >= 0:
carry += int(a[i])
i -= 1
if j >= 0:
carry += int(b[j])
j -= 1
s.append(str(carry % 2))
carry //= 2
return ''.join(reversed(s))
new Solution().addBinary()
Score: 5
Category: leetcode