Jewels and Stones LeetCode solution in Java

1
class Solution {
2
public int numJewelsInStones(String jewels, String stones) {
3
HashSet<Character> hs = new HashSet<>();
4
int count = 0;
5
for (int i = 0; i < jewels.length(); i++) {
6
hs.add(jewels.charAt(i));
7
}
8
for (int i = 0; i < stones.length(); i++) {
9
if (hs.contains(stones.charAt(i))) count++;
10
}
11
return count;
12
}
13
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0