2025-08-16 07:22:08 +0000 UTC

Check if Word Equals Summation of Two Words

Code

class Solution:
    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:
        def count(word: str) -> int:
            length = len(word)
            res = 0
            for i in reversed(range(length)):
                res += (ord(word[i]) - 97) * (10 ** (length - i - 1))
            return res
        return count(firstWord) + count(secondWord) == count(targetWord)