Skip to content

Commit a369f9c

Browse files
Added solution
1 parent 2b3a1fa commit a369f9c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

find_all_anagrams_of_substring.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> findAnagrams(string s, string p) {
4+
vector<int> goal(26), cur(26), res;
5+
6+
for(char c : p) goal[c - 'a']++;
7+
8+
for(int i = 0; i < s.size(); i++) {
9+
cur[s[i] - 'a']++;
10+
if(i >= p.size()) cur[s[i - p.size()] - 'a']--;
11+
if(cur == goal) res.push_back(i - p.size() + 1);
12+
}
13+
return res;
14+
}
15+
};

0 commit comments

Comments
 (0)