[LeetCode] 771. Jewels and Stones

원숭2·2022년 2월 15일
0

LeetCode

목록 보기
45/51

문제

풀이

  1. jewels에서 for문을 돌며 각 문자열에 대한 갯수를 결과에 더해줌.
  2. Counter를 사용하면 각 문자에 대한 갯수를 확인할 수 있음.

코드

from collections import Counter

class Solution:
    def numJewelsInStones(self, jewels: str, stones: str) -> int:
        res = 0
        for j in jewels :
            tmp = Counter(stones)[j]
            res += tmp
        
        return res

0개의 댓글