567. 字符串的排列

 

我写了首诗,把滑动窗口算法变成了默写题 | labuladong 的算法小抄 (gitee.io)

windows放窗口里需要统计的元素 

class Solution {
public:
    bool checkInclusion(string s1, string s2) {
        int left = 0;
        int right = 0;
        int flag = 0;
        map need;
        for (int i = 0; i < s1.size(); i++)
        {
            need[s1[i]]++;
        }
        //cout< windows;
        char c;
        while (right < s2.size())
        {
            c = s2[right];
            right++;
            if (need.count(c))
            {
                windows[c]++;
                if (windows[c] == need[c])
                {
                    flag++;
                }
            }
            if (right - left == s1.size())
            {
                // cout<

你可能感兴趣的:(滑动窗口,c++)