We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4a4d8ef commit d07553eCopy full SHA for d07553e
permutation-in-string/permutation-in-string.cpp
@@ -0,0 +1,39 @@
1
+class Solution {
2
+public:
3
+
4
+ bool valid(unordered_map<char,int>& mp){
5
+ for(auto x: mp)
6
+ if(x.second != 0)
7
+ return false;
8
+ return true;
9
+ }
10
+ bool checkInclusion(string s1, string s2) {
11
+ // s1 <= s2
12
+ int k = s1.size();
13
+ int n = s2.size();
14
15
+ if(n < k)
16
17
18
+ unordered_map<char,int> mp;
19
+ for(auto x: s1)
20
+ mp[x]++;
21
22
+ for(int i = 0; i < k; i++){
23
+ mp[s2[i]]--;
24
25
26
+ if(valid(mp))
27
28
29
+ for(int i = k; i < n; i++){
30
31
+ mp[s2[i - k]]++;
32
33
34
35
36
37
38
39
+};
0 commit comments