2.17 ✅ Sliding Window

Sliding Window #

  • 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 3 题,第 76 题,第 209 题,第 424 题,第 438 题,第 567 题,第 713 题,第 763 题,第 845 题,第 881 题,第 904 题,第 978 题,第 992 题,第 1004 题,第 1040 题,第 1052 题。
	left, right := 0, -1

	for left < len(s) {
		if right+1 < len(s) && freq[s[right+1]-'a'] == 0 {
			freq[s[right+1]-'a']++
			right++
		} else {
			freq[s[left]-'a']--
			left++
		}
		result = max(result, right-left+1)
	}
  • 滑动窗口经典题。第 239 题,第 480 题。
No.TitleSolutionDifficultyTimeComplexitySpaceComplexityFavoriteAcceptance
0003Longest Substring Without Repeating CharactersGoMediumO(n)O(1)❤️33.8%
0030Substring with Concatenation of All WordsGoHard31.2%
0076Minimum Window SubstringGoHardO(n)O(n)❤️40.9%
0187Repeated DNA SequencesGoMedium47.0%
0209Minimum Size Subarray SumGoMedium45.0%
0219Contains Duplicate IIGoEasy42.6%
0220Contains Duplicate IIIGoHard22.1%
0239Sliding Window MaximumGoHardO(n * k)O(n)❤️46.3%
0395Longest Substring with At Least K Repeating CharactersGoMedium44.8%
0424Longest Repeating Character ReplacementGoMediumO(n)O(1)52.0%
0438Find All Anagrams in a StringGoMedium50.2%
0480Sliding Window MedianGoHardO(n * log k)O(k)❤️41.1%
0567Permutation in StringGoMediumO(n)O(1)❤️44.3%
0632Smallest Range Covering Elements from K ListsGoHard61.0%
0643Maximum Average Subarray IGoEasy43.7%
0658Find K Closest ElementsGoMedium46.8%
0713Subarray Product Less Than KGoMedium45.8%
0718Maximum Length of Repeated SubarrayGoMedium51.3%
0862Shortest Subarray with Sum at Least KGoHard26.0%
0904Fruit Into BasketsGoMedium43.7%
0930Binary Subarrays With SumGoMedium52.2%
0978Longest Turbulent SubarrayGoMediumO(n)O(1)❤️47.2%
0992Subarrays with K Different IntegersGoHardO(n)O(n)❤️54.6%
0995Minimum Number of K Consecutive Bit FlipsGoHardO(n)O(1)❤️51.2%
1004Max Consecutive Ones IIIGoMediumO(n)O(1)63.2%
1052Grumpy Bookstore OwnerGoMediumO(n log n)O(1)57.1%
1208Get Equal Substrings Within BudgetGoMedium48.6%
1234Replace the Substring for Balanced StringGoMedium37.2%
1423Maximum Points You Can Obtain from CardsGoMedium52.2%
1438Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitGoMedium48.3%
1658Minimum Operations to Reduce X to ZeroGoMedium37.6%
1695Maximum Erasure ValueGoMedium57.6%
1696Jump Game VIGoMedium46.1%
1763Longest Nice SubstringGoEasy61.5%
1984Minimum Difference Between Highest and Lowest of K ScoresGoEasy54.5%
——————————————————————-——-—————-—————————-————-————-

⬅️上一页

下一页➡️

Calendar Apr 8, 2023
Edit Edit this page
本站总访问量:  次 您是本站第  位访问者