Skip to content

Commit d7a6177

Browse files
Added day2 solution
1 parent 4f67240 commit d7a6177

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int numJewelsInStones(string J, string S) {
4+
if(J.size() == 0 or S.size() == 0) return 0;
5+
6+
map<char, int> stones;
7+
8+
for(int i=0; i<S.size();i++){
9+
if(stones.find(S[i]) == stones.end())
10+
stones[S[i]] = 1;
11+
else
12+
stones[S[i]]++;
13+
}
14+
int c = 0;
15+
for(char j:J){
16+
if(stones.find(j) != stones.end()){
17+
c+=stones[j];
18+
}
19+
}
20+
return c;
21+
}
22+
};

0 commit comments

Comments
 (0)