Skip to content

Commit ca2dae0

Browse files
refactor 771
1 parent 0834acd commit ca2dae0

File tree

1 file changed

+13
-34
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-34
lines changed

src/main/java/com/fishercoder/solutions/_771.java

+13-34
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,20 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6-
/**
7-
* 771. Jewels and Stones
8-
9-
You're given strings J representing the types of stones that are jewels, and S representing the stones you have.
10-
Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
11-
The letters in J are guaranteed distinct, and all characters in J and S are letters.
12-
Letters are case sensitive, so "a" is considered a different type of stone from "A".
13-
14-
Example 1:
15-
Input: J = "aA", S = "aAAbbbb"
16-
Output: 3
17-
18-
Example 2:
19-
Input: J = "z", S = "ZZ"
20-
Output: 0
21-
22-
Note:
23-
S and J will consist of letters and have length at most 50.
24-
The characters in J are distinct.
25-
*/
26-
276
public class _771 {
28-
public static class Solution1 {
29-
public int numJewelsInStones(String J, String S) {
30-
Set<Character> set = new HashSet<>();
31-
for (char c : J.toCharArray()) {
32-
set.add(c);
33-
}
34-
int count = 0;
35-
for (char c : S.toCharArray()) {
36-
if (set.contains(c)) {
37-
count++;
7+
public static class Solution1 {
8+
public int numJewelsInStones(String J, String S) {
9+
Set<Character> set = new HashSet<>();
10+
for (char c : J.toCharArray()) {
11+
set.add(c);
12+
}
13+
int count = 0;
14+
for (char c : S.toCharArray()) {
15+
if (set.contains(c)) {
16+
count++;
17+
}
18+
}
19+
return count;
3820
}
39-
}
40-
return count;
4121
}
42-
}
4322
}

0 commit comments

Comments
 (0)