파이썬 알고리즘 인터뷰 11장_해시 테이블_2022_01_19(보석과 돌)

leeseungsoo0701·2022년 1월 19일
0
post-thumbnail

"""
J는 보석이며, S는 갖고 있는 돌이다. S에는 보석이 몇개나 있을까?
대소문자는 구분한다.

아이디어: 긴 문자열에 해당하는 것들의 in을 사용하면 어차피 하나씩 나온다 그것 중 J에 있는지 확인만하고 있으면 count +=1을 해주면 된다.
"""


def numJS(J:str, S:str) -> int:
    count = 0
    for s in S:
        if s in J:
            count +=1
    return count



J = "aA"
S = "aAAbbbb"
print(numJS(J,S))

링크 : https://github.com/leeseungsoo0701/python_alogrithm/blob/main/hash/leetcode/771_jewels_and_stones.py

leetcode 771

profile
한 줄이라도 정확하고 깊게 알아가보자 늦어도 좋다.

0개의 댓글

관련 채용 정보