[LeetCode] 389. Find the Difference

원숭2·2022년 2월 7일
0

LeetCode

목록 보기
34/51

문제

풀이

  1. Counter 메소드끼리 뺄셈을 이용함.
  2. elements함수로 Counter의 숫자만큼 요소를 list형태로 반환 받은 후, join함수를 사용하여 문자열 형태로 return함.

코드

from collections import Counter

class Solution:
    def findTheDifference(self, s: str, t: str) -> str:
        cs = Counter(s)
        ct = Counter(t)
        
        return ''.join(list((ct - cs).elements()))

0개의 댓글