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;
    }
};
相关推荐
驭渊的小故事20 分钟前
LeetCode 33:搜索旋转排序数组——从二分查找到旋转数组的区间判定
算法·leetcode·职场和发展
郝学胜-神的一滴1 天前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
CoderYanger1 天前
A.每日一题:2243. 计算字符串的数字和
java·开发语言·程序人生·leetcode·面试·蓝桥杯·学习方法
Navigator_Z1 天前
LeetCode //C - 1323. Maximum 69 Number
c语言·算法·leetcode
Pniubi3 天前
力扣2 . 两数相加
算法·leetcode·职场和发展
文丑颜不良啊3 天前
LeetCode3401~3420题目解析
java·leetcode
文丑颜不良啊3 天前
LeetCode3421~3440题目解析
java·leetcode
LK_074 天前
【力扣】142. 环形链表 II |Python
python·leetcode·链表
Pniubi4 天前
力扣21合并两个有序链表
算法·leetcode·职场和发展
文丑颜不良啊4 天前
LeetCode3341~3360题目解析
java·leetcode