leetcode 1880. 检查某单词是否等于两单词之和

class Solution:
    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:
        def f(word):
            res = 0
            for i in word:
                res *= 10
                res += ord(i) - ord('a')
            return res
        
        return f(firstWord) + f(secondWord) == f(targetWord)

猜你喜欢

转载自blog.csdn.net/milk_paramecium/article/details/122588972