2
def isSolvable(self, words: List[str], result: str) -> bool:5
words = [i[::-1] for i in words]7
allWords = words + [result]9
# chars that can not be 015
# numbers selected in backtracking19
mxLen = max([len(i) for i in allWords])21
def res(i=0, c=0, sm=0):23
return 1 if sm == 0 else 029
return res(0, c + 1, carry)32
# result[c] should be mapped to num if a mapping exists33
if result[c] in charToInt:34
if charToInt[result[c]] != num:37
return res(0, c + 1, carry)40
# if mapping does not exist, create a mapping41
elif (num == 0 and result[c] not in nonZero) or num > 0:43
charToInt[result[c]] = num44
ret = res(0, c + 1, carry)45
del charToInt[result[c]]53
return res(i + 1, c, sm)54
elif word[c] in charToInt:55
return res(i + 1, c, sm + charToInt[word[c]])58
# possibilities for word[c]60
if (j == 0 and word[c] not in nonZero) or j > 0:63
charToInt[word[c]] = j64
ret += res(i + 1, c, sm + j)65
del charToInt[word[c]]