카테고리 없음

[LeetCode with Python] 389. Find the Difference

papajohns 2020. 7. 12. 22:22

Difficulty : Easy

Approach : use alphabet map and save each letter's count. And compare



class Solution:
    def findTheDifference(self, s: str, t: str) -> str:
        answer = ""

        s_dict = {}        
        t_dict = {}

        for i in range(97, 123):
            s_dict[chr(i)] = 0
            t_dict[chr(i)] = 0

        for letter in s:
            s_dict[letter] += 1

        for letter in t:
            t_dict[letter] += 1

        for letter in s_dict:
            if s_dict[letter] != t_dict[letter]:
                answer = letter
                return answer

        return answer