-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path567.cpp
36 lines (36 loc) · 825 Bytes
/
567.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
class Solution {
public:
bool match(int A[],int B[]){
for(int i=0;i<26;i++){
if(A[i]!=B[i]){
return 0;
}
}
return 1;
}
bool checkInclusion(string s1, string s2) {
if(s1.length()>s2.length()){
return 0;
}
int A[26];
for(int i=0;i<26;i++){
A[i]=0;
}
for(int i=0;i<s1.length();i++){
A[s1[i]-'a']++;
}
for(int i=0;i<=(s2.length()-s1.length());i++){
int B[26];
for(int i=0;i<26;i++){
B[i]=0;
}
for(int j=0;j<s1.length();j++){
B[s2[i+j]-'a']++;
}
if(match(A,B)){
return 1;
}
}
return 0;
}
};