File tree 1 file changed +13
-34
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +13
-34
lines changed Original file line number Diff line number Diff line change 3
3
import java .util .HashSet ;
4
4
import java .util .Set ;
5
5
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
-
27
6
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 ;
38
20
}
39
- }
40
- return count ;
41
21
}
42
- }
43
22
}
You can’t perform that action at this time.
0 commit comments