func addStrings(num1 string, num2 string) string {
add := 0 //进位标志
ans := ""//最终字符串
var i = len(num1)-1//从末尾开始
var j = len(num2)-1//从末尾开始
for i >= 0 || j >= 0 || add != 0 {
var x, y int
if i >= 0 {
x = int(num1[i] - ‘0‘)
}
if j >= 0 {
y = int(num2[j] - ‘0‘)
}
result := x + y + add
ans = strconv.Itoa(result%10) + ans//每次拼接一位
add = result / 10
i--
j--
}
return ans
}
原文:https://www.cnblogs.com/pangqianjin/p/14635050.html