###415. Add Strings

题目:
<https://leetcode.com/problems/add-strings/>


难度:
Easy


照抄2. Add Two Numbers的代码，超时

```
class Solution(object):
    def addStrings(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        if num1 == '' or num1 == '0':
        	return num2
        if num2 == '' or num2 == '0':
        	return num1
        if int(num1[-1]) + int(num2[-1]) < 10:
        	num3 = str(int(num1[-1]) + int(num2[-1]) )
        	return self.addStrings(num1[:-1] , num2[:-1]) + num3
        else:
        	num3 = str(int(num1[-1]) + int(num2[-1]) - 10)
        	return self.addStrings(self.addStrings(num1[:-1] , num2[:-1]),'1') + num3
```



换成迭代，并非递归再来尝试，看了别人的代码，真是精巧啊


```
class Solution(object):
    def addStrings(self, num1, num2):
        """
        :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))
        print result
        return ''.join(result[::-1])  # 这里是reverse一下
```