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