655.Big Integer Addition
1.Description(Easy)
Given two non-negative integersnum1andnum2represented as string, return the sum ofnum1andnum2.
Notice
The length of both num1 and num2 is < 5100.
Both num1 and num2 contains only digits 0-9.
Both num1 and num2 does not contain any leading zero.
You must not use any built-in BigInteger library or convert the inputs to integer directly.
Example
Given num1 ="123", num2 ="45"
return"168"
2.Code
乘法的答案在这里:http://www.jiuzhang.com/solutions/big-integer-multiplication/
跟167 Add two number基本一样,需要一个carry控制进位。
需要注意的是把char转换成int的时候要用num.charAt(i)-'0',而不能直接强制转换(int).
Last updated
Was this helpful?