-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
771.cpp
45 lines (44 loc) · 1.11 KB
/
771.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
int numJewelsInStones(string J, string S) {
int a = J.size();
int b = S.size();
int num = 0;
for(int i = 0; i < a; ++i)
{
for(int j = 0; j < b; ++j)
{
if(J[i]==S[j])
{
++num;
}
}
}
return num;
}
};
__________________________________________________________________________________________________
sample 8172 kb submission
static const auto _____ = []()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
int numJewelsInStones(string J, string S) {
char has[256] = {0};
for(auto & a :J){
has[a] = 1;
}
int count = 0;
for(auto &a:S){
if(has[a]) ++count;
}
return count;
}
};
__________________________________________________________________________________________________