반응형
https://leetcode.com/problems/jewels-and-stones/
Jewels and Stones - 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
Think
오늘 푼 것 중에 제일 할 만 했던 것 같다^^..!
문제도 귀여웠음 보석찾기
해시테이블에 존재하는 키 값을 찾을 때 딕셔너리 자료형의 무슨 메서드가 있는지부터 고민했는데
단순히 in 연산자로 해결..~
파이썬에 더 익숙해지는 과정이 필요할 듯
Solution
class Solution(object):
def numJewelsInStones(self, jewels, stones):
"""
:type jewels: str
:type stones: str
:rtype: int
"""
#해시 테이블로 풀이
table = {}
#테이블에 개수 채워넣기
for s in stones :
if s not in table :
table[s] = 1
else :
table[s] += 1
count = 0
for j in jewels :
if j in table :
count += table[j]
return count
Get
- A not in B
반응형
'DSA > Algorithm' 카테고리의 다른 글
[LeetCode 77] Combinations (0) | 2022.10.04 |
---|---|
[LeetCode 17] Letter Combinations of a Phone Number (1) | 2022.10.04 |
[LeetCode 622] Design Circular Queue (0) | 2022.09.27 |
[LeetCode 225] Implement Stack using Queues (0) | 2022.09.27 |
[LeetCode 316] Remove Duplicate Letters (RE 다른풀이) (0) | 2022.09.27 |