소프트웨어에 대한 모든 것

LeetCode 풀기 - 1880. Check if Word Equals Summation of Two Words 본문

카테고리 없음

LeetCode 풀기 - 1880. Check if Word Equals Summation of Two Words

앤테바 2021. 12. 31. 07:08
반응형

1880. Check if Word Equals Summation of Two Words

https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/

 

Check if Word Equals Summation of Two Words - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

문제)

솔루션1)

class Solution:
    def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool:
        
        d = {c: str(i) for i, c in enumerate("abcdefghij") }
        def word_to_int(word):
            res = [d[c] for c in word]
            return int(''.join(res))
    
        a = word_to_int(firstWord)
        b = word_to_int(secondWord)
        c = word_to_int(targetWord)
        return (a+b) == c

 

 

반응형
Comments