-
[hash] jewels and stonesAlgorithm/LeetCode 2025. 4. 8. 09:52
✅ Problem
https://leetcode.com/problems/jewels-and-stones/description/
✅ Approach & Solution
방식) HashSet 사용
더보기class Solution { public int numJewelsInStones(String jewels, String stones) { int cnt = 0; Set<Character> jSet = new HashSet<>(); for (Character c : jewels.toCharArray()) { jSet.add(c); } for (Character c : stones.toCharArray()) { if (jSet.contains(c)) { cnt += 1; } } return cnt; } }
'Algorithm > LeetCode' 카테고리의 다른 글
[linked list] add two numbers (0) 2025.04.20 [linked list] reverse linked list (0) 2025.04.20 [array] best time to buy and sell stock 2 (0) 2025.04.07 [array] maximum product subarray (0) 2025.04.06 [array] 3sum closest (0) 2025.04.05