Advertisement
yarin0600

Untitled

Sep 22nd, 2023
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <vector>
  4. #include <string>
  5. #include <unordered_map>
  6.  
  7. std::vector<int> findAnagrams(std::string, std::string);
  8.  
  9. int main()
  10. {
  11. }
  12.  
  13. std::vector<int> findAnagrams(std::string s, std::string p)
  14. {
  15.    std::array<int, 26> pCountingArray{}, sCountingArray{};
  16.  
  17.    const size_t sSize = s.size();
  18.  
  19.    for (char curChar : p)
  20.       ++pCountingArray[curChar - 'a'];
  21.  
  22.    for (size_t left{}, right{}, matches{}; right < sSize; ++right)
  23.    {
  24.       //    r
  25.       // l
  26.       // cbbcaeabc
  27.       // pCountingArray = bbca
  28.       size_t currentCharIdx = s[right] - 'a';
  29.       // two cases:
  30.       // currentCharIdx is part of the solution / not part of the solution
  31.       if (++sCountingArray[currentCharIdx] > pCountingArray[currentCharIdx])
  32.       {
  33.       }
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement