题解 | #大数加法#
大数加法
http://www.nowcoder.com/practice/11ae12e8c6fe48f883cad618c2e81475
代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
计算两个数之和
@param s string字符串 表示第一个整数
@param t string字符串 表示第二个整数
@return string字符串
class Solution:
def solve(self, s, t):
full = 0
l1 = len(s)
l2 = len(t)
result = ''
maxLen = max(l1, l2)
for i in range(0,maxLen):
if i<l1:
x1 = int(s[l1-i-1])
else:
x1 = 0
if i< l2:
x2 = int(t[l2-i-1])
else:
x2 = 0
tem = x1 + x2 + full
if tem >= 10 :
result += (str(tem-10))
full = 1
else:
result += (str(tem))
full = 0
if full > 0 :
result += '1'
return result[::-1]