1. 定長滑動窗口
1.1 基礎
- 1456. Maximum Number of Vowels in a Substring of Given Length(1263)
- 643. Maximum Average Subarray I
- 1343. Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold(1317)
- 2090. K Radius Subarray Averages(1358)
- 2379. Minimum Recolors to Get K Consecutive Black Blocks(1360)
- 1052. Grumpy Bookstore Owner(1418)
- 1461. Check If a String Contains All Binary Codes of Size K(1504)
- 2841. Maximum Sum of Almost Unique Subarray(1546)
- 2461. Maximum Sum of Distinct Subarrays With Length K(1553)
- 1423. Maximum Points You Can Obtain from Cards(1574)
- 1652. Defuse the Bomb
- 1297. Maximum Number of Occurrences of a Substring(1748)
- 1176. Diet Plan Performance(會員題)
- 1100. Find K-Length Substrings With No Repeated Characters(會員題)
- 1852. Distinct Numbers in Each Subarray(會員題)
- 1151. Minimum Swaps to Group All 1’s Together(會員題)
- 2107. Number of Unique Flavors After sharing K Candies(會員題)
1.2 進階
- 2134. Minimum Swaps to Group All 1’s Together II(1748)
- 2653. Sliding Subarray Beauty(1786)
- 1888. Minimum Number of Flips to Make the Binary String Alternating(2006)
- 567. Permutation in String
- 438. Find All Anagrams in a String
- 30. Substring with Concatenation of All Words
- 2156. Find Substring With Given Hash Value(2063)
- 2953. Count Complete Substrings(2449)
- 1016. Binary String With Substrings Representing 1 To N
- 683. K Empty Slots(會員題)
- 2067. Number of Equal Count Substrings(會員題)
- 2524. Maximum Frequency Score of a substring(會員題)
1.3 其它
- 2269. Find the K-Beauty of a Number(1280)
- 1984. Minimum Difference Between Highest and Lowest of K Scores(1306)
- 220. Contains Duplicate III
2. 不定長滑動窗口
不定長滑動窗口主要分為三類:求最長子數組、求最短子數組,以及求子數組個數。
2.1 求最長/最大
- 3. Longest Substring Without Repeating Characters
- 3090. Maximum Length Substring With Two Occurrences(1329)
- 1493. Longest Subarray of 1’s After Deleting One Element(1423)
- 1208. Get Equal Substrings Within Budget(1497)
- 2730. Find the Longest Semi-Repetitive Substring(1502)
- 904. Fruit Into Baskets(1516)
- 1695. Maximum Erasure Value(1529)
- 2958. Length of Longest Subarray With at Most K Frequency(1535)
- 2779. Maximum Beauty of an Array After Applying Operation(1638)
- 2024. Maximize the Confusion of an Exam(1643)
- 1004. Max Consecutive Ones III(1656)
- 1658. Minimum Operations to Reduce X to Zero(1817)
- 1838. Frequency of the Most Frequent Element(1876)
- 2516. Take K of Each Character From Left and Right(1948)
- 2831. Find the Longest Equal Subarray(1976)
- 2271. Maximum White Tiles Covered by a Carpet(2022)
- 2106. Maximum Fruits Harvested After at Most K Steps(2062)
- 2555. Maximize Win From Two Segments(2081)
- 2009. Minimum Number of Operations to Make Array Continuous(2084)
- 1610. Maximum Number of Visible Points(2147)
- 2781
- 3411
- 2968
- 1040
- 3413
- [395]
- [1763]
- 487
- 159
2.2 求最短/最小
一般題目都有「至少」的要求。
2.3 求子數組個數
2.3.1 越長越合法
一般要寫
res += left
滑動窗口的內層循環結束時,右端點固定在right
,左端點在0,1,2,...,left-1
的所有子數組(子串)都是合法的,這一共有left
個。
2.3.2 越短越合法
2.3.3 恰好型滑動窗口
2.4 其他(選做)
3.1 相向雙指针
- [344]
- [125]
- 1750
- 2105
- [977]
- [658]
- [1471]
- [167]
- [633]
- [2824]
- [15]
- [16]
- [18]
- [611]
- [1577]
- 923
- 948
- [11]
- [42]
- 1616
- 1498
- 1782
- 1099
- 360
- 2422
- 259
3.2 同向雙指针
3.3 背向雙指针
3.4 原地修改
- [27]
- [26]
- [80]
- [283]
- [905]
- [922]
- [2460]
- [1089]