655.Big Integer Addition
Last updated
Was this helpful?
Last updated
Was this helpful?
Given two non-negative integersnum1
andnum2
represented as string, return the sum ofnum1
andnum2
.
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"
乘法的答案在这里:
跟167 Add two number基本一样,需要一个carry控制进位。
需要注意的是把char转换成int的时候要用num.charAt(i)-'0',而不能直接强制转换(int).