[LeetCode]415. Add Strings
题目
Given two non-negative integers num1
and num2
represented as string, return the sum of num1
and num2
.
Note:
- 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.
难度
Easy
方法
从低位到高位相加,每一位的结果为除10取余,如果有进位1,则在下一位求和的时候需要+1,循环处理即可。注意最高位相加后如果有进位,需要在结果的最前面补1
python代码
1 | class Solution(object): |