Skip to content

Commit e5f7122

Browse files
committed
Time: 3 ms (95.8%), Space: 7.6 MB (45.37%) - LeetHub
1 parent 561e393 commit e5f7122

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
bool checkInclusion(string s1, string s2) {
4+
if(s1.size() > s2.size())
5+
return false;
6+
vector<int> v(26, 0), temp (26, 0);
7+
for (int i = 0; i < s1.size(); i++) {
8+
v[s1[i] - 'a']++;
9+
temp[s2[i] - 'a']++;
10+
}
11+
if(v == temp)
12+
return true;
13+
int n = s2.size() - s1.size();
14+
for (int i = 0; i < n; i++) {
15+
temp[s2[i] - 'a']--;
16+
temp[s2[s1.size() + i] - 'a']++;
17+
if(v == temp)
18+
return true;
19+
}
20+
return false;
21+
}
22+
};

0 commit comments

Comments
 (0)