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;
    }
};
相关推荐
smj2302_796826523 小时前
解决leetcode第3869题.统计区间内奇妙数的数目
python·算法·leetcode
TracyCoder1233 小时前
LeetCode Hot100(66/100)——118. 杨辉三角
算法·leetcode·职场和发展
葳_人生_蕤3 小时前
Leetcode HOT 100
算法·leetcode·职场和发展
无尽的罚坐人生3 小时前
hot 100 35. 搜索插入位置
数据结构·算法·leetcode·二分查找
葳_人生_蕤3 小时前
力扣Hot100——234.回文链表
算法·leetcode·链表
luckycoding5 小时前
1487. 保证文件名唯一
数据结构·算法·leetcode
big_rabbit05025 小时前
[算法][力扣110]平衡二叉树
数据结构·算法·leetcode
TracyCoder1237 小时前
LeetCode Hot100(70/100)—— 322. 零钱兑换
算法·leetcode·职场和发展
x_xbx7 小时前
LeetCode:88. 合并两个有序数组
算法·leetcode·职场和发展