Skip to content

Commit 788cbde

Browse files
authored
Create jewels-and-stones.cpp
1 parent d88da35 commit 788cbde

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/jewels-and-stones.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(m + n)
2+
// Space: O(n)
3+
4+
class Solution {
5+
public:
6+
int numJewelsInStones(string J, string S) {
7+
unordered_set<char> lookup;
8+
for (const auto& j : J) {
9+
lookup.emplace(j);
10+
}
11+
int result = 0;
12+
for (const auto& s : S) {
13+
result += lookup.count(s);
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)