## 题目描述：

IMPORTANT:
Solutions which uses a BigInteger library or converting the input strings to another type (such as integer) will result in disqualification of all submissions to this problem.
After the contest ends, users can view accepted submissions code and report cheating solutions.

Given two non-negative numbers `num1` and `num2` represented as string, return the sum of `num1` and `num2`.

Note:

1. The length of both `num1` and `num2` is < 5100.
2. Both `num1` and `num2` contains only digits `0-9`.
3. Both `num1` and `num2` does not contain any leading zero.
4. You must not use any built-in BigInteger library or convert the inputs to integer directly.

## 题目大意：

1. num1和num2的长度< 5100
2. num1和num2只包含数字0-9
3. num1和num2不包含前导0

## Python代码：

``````class Solution(object):
"""
:type num1: str
:type num2: str
:rtype: str
"""
result = []
carry = 0
idx1, idx2 = len(num1), len(num2)
while idx1 or idx2 or carry:
digit = carry
if idx1:
idx1 -= 1
digit += int(num1[idx1])
if idx2:
idx2 -= 1
digit += int(num2[idx2])
carry = digit > 9
result.append(str(digit % 10))
return ''.join(result[::-1])
``````

Pingbacks已关闭。