力扣415. 字符串相加

原题

 1 class Solution:
 2     def addStrings(self, num1: str, num2: str) -> str:
 3         ans = ""
 4         i,j,carry=len(num1)-1,len(num2)-1,0
 5         while i >=0 or j >= 0:
 6             s = carry
 7             if i >= 0:
 8                 s += int(num1[i])
 9                 i -= 1
10             if j >= 0:
11                 s += int(num2[j])
12                 j -= 1
13             carry = s // 10
14             ans += str(s % 10)
15         ans += '1' if carry == 1 else ''
16         return ans[::-1]
原文地址:https://www.cnblogs.com/deepspace/p/14322045.html