题解 | #大数加法#
大数加法
http://www.nowcoder.com/practice/11ae12e8c6fe48f883cad618c2e81475
package main
import "strconv"
func solve( s string , t string ) string {
tmp, n, m := 0, len(s)-1, len(t)-1
result := ""
for n >= 0 || m >= 0 || tmp != 0 {
i, j := 0, 0
if n >= 0 {
i = int(s[n] - '0')
n--
}
if m >= 0 {
j = int(t[m] - '0')
m--
}
tmp += i + j
result = strconv.Itoa(tmp%10) + result
tmp = tmp / 10
}
return result
}