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.1%
0030Substring with Concatenation of All WordsGoHard28.2%
0076Minimum Window SubstringGoHardO(n)O(n)❤️39.1%
0187Repeated DNA SequencesGoMedium44.8%
0209Minimum Size Subarray SumGoMedium43.4%
0219Contains Duplicate IIGoEasy40.7%
0220Contains Duplicate IIIGoMedium21.7%
0239Sliding Window MaximumGoHardO(n * k)O(n)❤️46.2%
0395Longest Substring with At Least K Repeating CharactersGoMedium44.6%
0424Longest Repeating Character ReplacementGoMediumO(n)O(1)50.8%
0438Find All Anagrams in a StringGoMedium48.3%
0480Sliding Window MedianGoHardO(n * log k)O(k)❤️41.0%
0567Permutation in StringGoMediumO(n)O(1)❤️44.6%
0632Smallest Range Covering Elements from K ListsGoHard58.6%
0643Maximum Average Subarray IGoEasy43.5%
0713Subarray Product Less Than KGoMedium43.9%
0718Maximum Length of Repeated SubarrayGoMedium51.3%
0862Shortest Subarray with Sum at Least KGoHard26.2%
0904Fruit Into BasketsGoMedium42.8%
0930Binary Subarrays With SumGoMedium48.9%
0978Longest Turbulent SubarrayGoMediumO(n)O(1)❤️47.5%
0992Subarrays with K Different IntegersGoHardO(n)O(n)❤️53.4%
0995Minimum Number of K Consecutive Bit FlipsGoHardO(n)O(1)❤️50.7%
1004Max Consecutive Ones IIIGoMediumO(n)O(1)63.0%
1052Grumpy Bookstore OwnerGoMediumO(n log n)O(1)56.7%
1208Get Equal Substrings Within BudgetGoMedium46.6%
1234Replace the Substring for Balanced StringGoMedium36.3%
1423Maximum Points You Can Obtain from CardsGoMedium50.1%
1438Longest Continuous Subarray With Absolute Diff Less Than or Equal to LimitGoMedium46.5%
1658Minimum Operations to Reduce X to ZeroGoMedium33.6%
1695Maximum Erasure ValueGoMedium52.4%
1696Jump Game VIGoMedium42.7%
1763Longest Nice SubstringGoEasy61.7%
1984Minimum Difference Between Highest and Lowest of K ScoresGoEasy53.5%
——————————————————————-——-—————-—————————-————-————-

⬅️上一页

下一页➡️

Calendar May 20, 2022
Edit Edit this page
本站总访问量:  次 您是本站第  位访问者