File tree Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Expand file tree Collapse file tree 1 file changed +20
-11
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
public int numJewelsInStones (String jewels , String stones ) {
3
3
4
- Set <Character > set = new HashSet <>();
5
4
int count =0 ;
6
- for (char ch : jewels .toCharArray ()){
7
- set .add (ch );
8
- }
9
-
10
- for (char stone : stones .toCharArray ()){
11
- if (set .contains (stone )){
12
- count ++;
5
+ for (char jewel : jewels .toCharArray ()){
6
+ for (char stone : stones .toCharArray ()){
7
+ if (jewel ==stone ){
8
+ count ++;
9
+ }
13
10
}
14
11
}
15
- return count ;
16
-
12
+ return count ;
17
13
}
18
- }
14
+ }
15
+
16
+ // Set<Character> set = new HashSet<>();
17
+ // int count=0;
18
+ // for(char ch : jewels.toCharArray()){
19
+ // set.add(ch);
20
+ // }
21
+
22
+ // for(char stone : stones.toCharArray()){
23
+ // if(set.contains(stone)){
24
+ // count++;
25
+ // }
26
+ // }
27
+ // return count;
You can’t perform that action at this time.
0 commit comments