Skip to content

Commit 53bb7a1

Browse files
Merge pull request PawanJaiswal08#27 from iparthtripathi/Parth-Tripathi
Create code.cpp
2 parents d957a2c + 8a69ac7 commit 53bb7a1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Solution {
2+
3+
4+
private:
5+
bool checkEqual(int arr1[26],int arr2[26]){
6+
for(int i=0;i<26;i++){
7+
if(arr1[i]!=arr2[i])
8+
return 0;
9+
}
10+
return 1;
11+
}
12+
public:
13+
bool checkInclusion(string s1, string s2) {
14+
15+
int arr1[26]={0},n;
16+
for(int i=0;i<s1.length();i++){
17+
n=s1[i]-'a';
18+
arr1[n]++;
19+
}
20+
21+
int arr2[26]={0};
22+
int i=0,window=s1.length();
23+
24+
while(i<window&&i<s2.length()){
25+
n=s2[i]-'a';
26+
arr2[n]++;
27+
i++;
28+
}
29+
if(checkEqual(arr1,arr2))
30+
return 1;
31+
32+
while(i<s2.length()){
33+
int index=s2[i]-'a';
34+
arr2[index]++;
35+
index=s2[i-window]-'a';
36+
arr2[index]--;
37+
i++;
38+
if(checkEqual(arr1,arr2))
39+
return 1;
40+
}
41+
return 0;
42+
}
43+
};

0 commit comments

Comments
 (0)