10000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d2ce2e3 + 2eba7a2 commit 29641c8Copy full SHA for 29641c8
May-LeetCoding-Challenge/18-Permutation-In-String/Permutation-In-String.cpp
@@ -30,4 +30,30 @@ class Solution {
30
31
return false;
32
}
33
-};
+};
34
+
35
+class Solution2 {
36
+public:
37
+ bool checkInclusion(string s1, string s2) {
38
+ vector<int> h1(26,0);
39
+ int count = s1.size();
40
+ int right = 0, left = 0;
41
+ int l_idx;
42
43
+ for (char &c : s1) ++h1[c-'a'];
44
45
+ for (int right = 0; right < s2.size() ; ++right) {
46
+ count -= h1[s2[right]-'a']-- > 0;
47
+ if (count == 0) {
48
+ l_idx = right - s1.size() + 1;
49
+ for (; left < l_idx; ++left)
50
+ count += h1[s2[left]-'a']++ >= 0;
51
52
+ if (count == 0)
53
+ return true;
54
+ }
55
56
57
+ return false;
58
59
0 commit comments