본문 바로가기
python-algorithm

leetcode 1880. Check if Word Equals Summation of Two Words

by 무적김두칠 2022. 3. 21.

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str-> bool:
        wordToint1=''
        wordToint2=''
        wordToint3=''
        for i in firstWord: wordToint1+=str(ord(i)-97)
        for i in secondWord: wordToint2+=str(ord(i)-97)
        for i in targetWord: wordToint3+=str(ord(i)-97)
        
        if int(wordToint1)+int(wordToint2)==int(wordToint3) : return True
        elsereturn False
cs
반응형

댓글