题解 | #大数加法#
大数加法
https://www.nowcoder.com/practice/11ae12e8c6fe48f883cad618c2e81475
class Solution:
def solve(self, s: str, t: str) -> str:
# write code here
if s == "0":
return t
if t == "0":
return s
idx1, idx2 = len(s) - 1, len(t) - 1
carry = 0
res = ""
while idx1 >= 0 or idx2 >= 0 or carry:
if idx1 >= 0:
carry += int(s[idx1])
idx1 -= 1
if idx2 >= 0:
carry += int(t[idx2])
idx2 -= 1
res += str(carry % 10)
carry //= 10
return res[::-1]

