-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJewelsAndStones.java
More file actions
44 lines (30 loc) · 807 Bytes
/
JewelsAndStones.java
File metadata and controls
44 lines (30 loc) · 807 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
36
37
38
39
40
41
42
43
44
package leetcode;
import sun.rmi.runtime.Log;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* 771 JewelsAndStones
* Created by solie_h on 2018/10/28.
*/
public class JewelsAndStones {
public static int numJewelsInStones(String J, String S) {
int outPut = 0;
Set set = new HashSet<Character>();
for (int i = 0; i < J.length(); i++) {
set.add(J.charAt(i));
}
for (int j = 0; j < S.length(); j++) {
if (set.contains(S.charAt(j))) {
outPut++;
}
}
return outPut;
}
public static void main(String[] args) {
String J = "aA";
String S = "aAAbbbb";
System.out.println(numJewelsInStones(J,S));
}
}