滑动窗口
Contents
适用于滑动窗口的题目的特点
滑动窗口模式
最短
- 先移动右指针,直至满足条件
- 再移动左指针,直至不满足条件
最长
- 先移动右指针,直至不满足条件
- 再移动左指针,直至满足条件
题目
无重复字符的最长子串
- 给定一个字符串,请找出其中不含有重复字符的最长子串的长度。
- https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
最小覆盖子串
- https://leetcode-cn.com/problems/minimum-window-substring/
- 关键在于如何判断窗口内是否包含了字符串 t 中的所有字符
- 用一个 count 记录在窗口中包含的字符串 t 的字符个数
找到字符串中所有字母异位词
- https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/
- 解决思路和
最小覆盖字串
相同,唯一的不同在于还需要判断right-left+1 == plen
.
长度最小的子数组
- https://leetcode-cn.com/problems/minimum-size-subarray-sum/
- 思路同最小覆盖子串一样,而且判断比最小覆盖字串简单多了!
滑动窗口最大值
- https://leetcode-cn.com/problems/sliding-window-maximum/
- 重点考察的是单调队列,而不是滑动窗口!
滑动窗口中位数
Author 段新朋
LastMod 2020-07-21