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;
    }
};
相关推荐
小肝一下2 小时前
每日两道力扣,day5
数据结构·c++·算法·leetcode·职场和发展·hot100
派大星~课堂8 小时前
【力扣-142. 环形链表2 ✨】Python笔记
python·leetcode·链表
会编程的土豆9 小时前
【数据结构与算法】动态规划
数据结构·c++·算法·leetcode·代理模式
6Hzlia10 小时前
【Hot 100 刷题计划】 LeetCode 78. 子集 | C++ 回溯算法题解
c++·算法·leetcode
py有趣15 小时前
力扣热门100题之接雨水
算法·leetcode
py有趣18 小时前
力扣热门100题之合并区间
算法·leetcode
派大星~课堂18 小时前
【力扣-138. 随机链表的复制 ✨】Python笔记
python·leetcode·链表
py有趣18 小时前
力扣热门100题之最小覆盖子串
算法·leetcode
北顾笙98019 小时前
day15-数据结构力扣
数据结构·算法·leetcode
人道领域20 小时前
【LeetCode刷题日记:24】两两交换链表
算法·leetcode·链表