> For the complete documentation index, see [llms.txt](https://blessbingo.gitbook.io/garnet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blessbingo.gitbook.io/garnet/suan-fa/zi-fu-chuan/415-zi-fu-chuan-xiang-jia.md).

# \[415]\[简单] 字符串相加

## 题目描述

给定两个字符串形式的非负整数 num1 和num2 ，计算它们的和。

注意：

1. num1 和num2 的长度都小于 5100.
2. num1 和num2 都只包含数字 0-9.
3. num1 和num2 都不包含任何前导零。
4. 你不能使用任何內建 BigInteger 库， 也不能直接将输入的字符串转换为整数形式。

## 解题思路

简单的对位加减, 注意进位即可.

```python
class Solution:
    def addStrings(self, num1: str, num2: str) -> str:
        n, m = len(num1), len(num2)
        carry = 0

        col = []
        num1, num2 = num1[::-1], num2[::-1]
        print(num1, num2)
        b = max(n, m)
        for i in range(b):
            t1 = int(num1[i]) if i < n else 0
            t2 = int(num2[i]) if i < m else 0
            t_res = t1 + t2 + carry
            if t_res > 9:
                carry, t_res = 1, t_res - 10
            else:
                carry = 0
            col.append(str(t_res))

        if carry:
            col.append('1')

        return ''.join(col[::-1])
```
