python-codewars-solutions/sum_strings/solution.py

12 lines
347 B
Python
Raw Permalink Normal View History

2024-01-23 13:32:21 +00:00
# https://www.codewars.com/kata/5324945e2ece5e1f32000370/
def sum_strings(s1, s2):
res = ""
carry = 0
s1, s2 = s1.zfill(len(s2)), s2.zfill(len(s1))
for d1, d2 in zip(s1[::-1], s2[::-1]):
carry, total = divmod(int(d1) + int(d2) + carry, 10)
res += str(total)
return (str(carry) + res[::-1]).lstrip('0') or '0'