Check if Word Equals Summation of Two Words LeetCode solution in Python

1
# Runtime: 40 ms (Top 58.1%) | Memory: 16.21 MB (Top 73.9%)
2

3

4
class Solution:
5
def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:
6
x = [
7
"a",
8
"b",
9
"c",
10
"d",
11
"e",
12
"f",
13
"g",
14
"h",
15
"i",
16
"j",
17
"k",
18
"l",
19
"m",
20
"n",
21
"o",
22
"p",
23
"q",
24
"r",
25
"s",
26
"t",
27
"u",
28
"v",
29
"w",
30
"x",
31
"y",
32
"z",
33
]
34
a = ""
35
for i in firstWord:
36
a = a + str(x.index(i))
37

38
b = ""
39
for i in secondWord:
40
b = b + str(x.index(i))
41

42
c = ""
43
for i in targetWord:
44
c = c + str(x.index(i))
45
if int(a) + int(b) == int(c):
46
return True
47
return False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0