415. Add Strings
https://leetcode.com/problems/add-strings/
Python
class Solution:
def addStrings(self, num1: str, num2: str) -> str:
result = []
carry = 0
string1 = list(num1)
string2 = list(num2)
while string1 or string2:
char1 = string1.pop() if string1 else '0'
char2 = string2.pop() if string2 else '0'
n1 = ord(char1) - ord('0')
n2 = ord(char2) - ord('0')
value = n1 + n2 + carry
carry = value // 10
result.append(value % 10)
if carry:
result.append(carry)
return ''.join([str(char) for char in result[::-1]])