-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSolution.java
More file actions
36 lines (29 loc) · 836 Bytes
/
Solution.java
File metadata and controls
36 lines (29 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.leetcode.minji;
import java.util.HashSet;
import java.util.Set;
/**
* 771. Jewels and Stones
* https://leetcode.com/problems/jewels-and-stones/
*/
public class Solution {
public int numJewelsInStones(String J, String S) {
Set<Character> jewels = new HashSet<>();
for (char j : J.toCharArray()) {
jewels.add(j);
}
int types = 0;
for (char s : S.toCharArray()) {
if (jewels.contains(s)) {
types += 1;
}
}
return types;
}
public static void main(String[] args) {
Solution solution = new Solution();
int res = solution.numJewelsInStones("aA", "aAAbbbb");
System.out.println(res);
res = solution.numJewelsInStones("z", "ZZ");
System.out.println(res);
}
}