Skip to content

Commit 3b6c9c7

Browse files
authored
Create check-if-word-equals-summation-of-two-words.py
1 parent cc53346 commit 3b6c9c7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def isSumEqual(self, firstWord, secondWord, targetWord):
6+
"""
7+
:type firstWord: str
8+
:type secondWord: str
9+
:type targetWord: str
10+
:rtype: bool
11+
"""
12+
def stoi(s):
13+
result = 0
14+
for c in s:
15+
result = result*10 + ord(c)-ord('a')
16+
return result
17+
18+
return stoi(firstWord) + stoi(secondWord) == stoi(targetWord)

0 commit comments

Comments
 (0)