788 B
788 B
layout, title, last_solved, category, leetcode_url, status
| layout | title | last_solved | category | leetcode_url | status |
|---|---|---|---|---|---|
| page | Add Strings | 2020-05-30 | math | https://leetcode.com/problems/add-strings/ | Attempted |
Problem
Given "12" and "3", return "15". You must not use any built-in BigInteger library or convert the inputs to integer directly.
Solution
Wasn't suppose to convert to integers
{% highlight python %}
def addStrings(self, num1: str, num2: str) -> str:
def itoa(num1):
sum=0
digitCol = 0
for i in reversed( range(len(num1)) ):
digit = ord(num1[i])-ord('0') # '2'-'0' = 2
sum += (digit * (10**digitCol))
digitCol+=1
return(sum)
return itoa(num1)+itoa(num2)
{% endhighlight %}