LCR 014.字符串的排列

文章目录

题意

题目链接

思路

滑动窗口

代码

C++ 复制代码
class Solution {
public:
    bool judge(int a[], int b[]) {
        for (int i = 0; i < 26; i++)
            if (a[i] != b[i])
                return false;
        return true;
    }
    bool checkInclusion(string s1, string s2) {
        int a[26] = {0};
        int b[26] = {0};
        if (s1.size() > s2.size())
            return false;
        for (int i = 0; i < s1.size(); i++) {
            a[s1[i] - 'a'] ++;
            b[s2[i] - 'a'] ++;
        }
        
        if (judge(a, b)) {
            return true;
        }
        for (int i = 0, j = s1.size(); j < s2.size(); i++, j++) {
            b[s2[i] - 'a']--;
            b[s2[j] - 'a']++;
            if (judge(a,b))
                return true;
        }
        return false;
    }
};
相关推荐
小羊在睡觉19 小时前
力扣239. 滑动窗口最大值
数据结构·后端·算法·leetcode·go
大大杰哥20 小时前
leetcode hot100(4)矩阵
算法·leetcode·矩阵
叶小鸡20 小时前
小鸡玩算法-力扣HOT100-动态规划(上)
算法·leetcode·动态规划
凌波粒21 小时前
LeetCode--513.找树左下角的值(二叉树)
java·算法·leetcode
一只小逸白1 天前
LeetCode Go 常用函数速查表
linux·leetcode·golang
Tisfy1 天前
LeetCode 3043.最长公共前缀的长度:哈希表(不转string)
算法·leetcode·散列表·题解·哈希表
承渊政道1 天前
【贪心算法】(经典实战应用解析(六):整数替换、俄罗斯套娃信封问题、可被三整除的最⼤和、距离相等的条形码、重构字符串)
c++·算法·leetcode·贪心算法·排序算法·动态规划·哈希算法
人道领域1 天前
【LeetCode刷题日记】654.最大二叉树:递归算法详解
java·算法·leetcode
失去的青春---夕阳下的奔跑2 天前
560. 和为 K 的子数组
数据结构·算法·leetcode
m0_629494732 天前
LeetCode 热题 100-----25.回文链表
数据结构·算法·leetcode·链表