Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <vector>
- #include <string>
- #include <unordered_map>
- std::vector<int> findAnagrams(std::string, std::string);
- int main()
- {
- }
- std::vector<int> findAnagrams(std::string s, std::string p)
- {
- std::array<int, 26> pCountingArray{}, sCountingArray{};
- const size_t sSize = s.size();
- for (char curChar : p)
- ++pCountingArray[curChar - 'a'];
- for (size_t left{}, right{}, matches{}; right < sSize; ++right)
- {
- // r
- // l
- // cbbcaeabc
- // pCountingArray = bbca
- size_t currentCharIdx = s[right] - 'a';
- // two cases:
- // currentCharIdx is part of the solution / not part of the solution
- if (++sCountingArray[currentCharIdx] > pCountingArray[currentCharIdx])
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement