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.
1 parent f540079 commit a715c00Copy full SHA for a715c00
leetcode/cpp/string/567.cpp
@@ -0,0 +1,32 @@
1
+class Solution {
2
+public:
3
+ bool checkInclusion(string sml, string lrg) {
4
+ if (lrg.length() < sml.length())
5
+ return false;
6
+
7
+ unordered_map<char, int> targetMap, haveMap;
8
+ for(char c: sml) {
9
+ targetMap[c]++;
10
+ }
11
12
+ for(char c: lrg.substr(0, sml.length())) {
13
+ haveMap[c]++;
14
15
16
+ int st=0, en=sml.length()-1;
17
+ while(en < lrg.length()) {
18
+ if (targetMap == haveMap) {
19
+ return true;
20
21
22
+ haveMap[lrg[st]]--;
23
+ if (haveMap[lrg[st]]==0) haveMap.erase(lrg[st]);
24
+ st++;
25
+ en++;
26
+ if (en<lrg.length())
27
+ haveMap[lrg[en]]++;
28
29
30
31
32
+};
0 commit comments