2.03 ✅ Two Pointers

Two Pointers #

  • 双指针滑动窗口的经典写法。右指针不断往右移,移动到不能往右移动为止(具体条件根据题目而定)。当右指针到最右边以后,开始挪动左指针,释放窗口左边界。第 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)
	}
  • 快慢指针可以查找重复数字,时间复杂度 O(n),第 287 题。
  • 替换字母以后,相同字母能出现连续最长的长度。第 424 题。
  • SUM 问题集。第 1 题,第 15 题,第 16 题,第 18 题,第 167 题,第 923 题,第 1074 题。
No.TitleSolutionDifficultyTimeComplexitySpaceComplexityFavoriteAcceptance
0003Longest Substring Without Repeating CharactersGoMediumO(n)O(1)❤️31.6%
0011Container With Most WaterGoMediumO(n)O(1)52.9%
00153SumGoMediumO(n^2)O(n)❤️28.3%
00163Sum ClosestGoMediumO(n^2)O(1)❤️46.3%
00184SumGoMediumO(n^3)O(n^2)❤️35.1%
0019Remove Nth Node From End of ListGoMediumO(n)O(1)35.9%
0026Remove Duplicates from Sorted ArrayGoEasyO(n)O(1)46.8%
0027Remove ElementGoEasyO(n)O(1)49.5%
0028Implement strStr()GoEasyO(n)O(1)35.4%
0030Substring with Concatenation of All WordsGoHardO(n)O(n)❤️26.4%
0042Trapping Rain WaterGoHardO(n)O(1)❤️51.6%
0061Rotate ListGoMediumO(n)O(1)32.0%
0075Sort ColorsGoMediumO(n)O(1)❤️49.8%
0076Minimum Window SubstringGoHardO(n)O(n)❤️36.2%
0080Remove Duplicates from Sorted Array IIGoMediumO(n)O(146.4%
0086Partition ListGoMediumO(n)O(1)❤️43.8%
0088Merge Sorted ArrayGoEasyO(n)O(1)❤️40.9%
0125Valid PalindromeGoEasyO(n)O(1)38.6%
0141Linked List CycleGoEasyO(n)O(1)❤️43.1%
0142Linked List Cycle IIGoMediumO(n)O(1)❤️40.0%
0167Two Sum II - Input array is sortedGoEasyO(n)O(1)55.8%
0209Minimum Size Subarray SumGoMediumO(n)O(1)39.8%
0234Palindrome Linked ListGoEasyO(n)O(1)42.0%
0283Move ZeroesGoEasyO(n)O(1)58.7%
0287Find the Duplicate NumberGoMediumO(n)O(1)❤️57.9%
0344Reverse StringGoEasyO(n)O(1)70.7%
0345Reverse Vowels of a StringGoEasyO(n)O(1)45.2%
0349Intersection of Two ArraysGoEasyO(n)O(n)65.3%
0350Intersection of Two Arrays IIGoEasyO(n)O(n)52.2%
0424Longest Repeating Character ReplacementGoMediumO(n)O(1)48.4%
0457Circular Array LoopGoMedium30.3%
0524Longest Word in Dictionary through DeletingGoMediumO(n)O(1)50.1%
0532K-diff Pairs in an ArrayGoMediumO(n)O(n)35.6%
0567Permutation in StringGoMediumO(n)O(1)❤️44.5%
0632Smallest Range Covering Elements from K ListsGoHard54.5%
0713Subarray Product Less Than KGoMediumO(n)O(1)40.6%
0763Partition LabelsGoMediumO(n)O(1)❤️78.1%
0826Most Profit Assigning WorkGoMediumO(n log n)O(n)39.3%
0828Count Unique Characters of All Substrings of a Given StringGoHardO(n)O(1)❤️46.9%
0838Push DominoesGoMediumO(n)O(n)50.0%
0844Backspace String CompareGoEasyO(n)O(n)47.2%
0845Longest Mountain in ArrayGoMediumO(n)O(1)38.7%
0881Boats to Save PeopleGoMediumO(n log n)O(1)49.1%
0904Fruit Into BasketsGoMediumO(n log n)O(1)43.0%
09233Sum With MultiplicityGoMediumO(n^2)O(n)41.0%
0925Long Pressed NameGoEasyO(n)O(1)37.3%
0930Binary Subarrays With SumGoMediumO(n)O(n)❤️44.8%
0977Squares of a Sorted ArrayGoEasyO(n)O(1)71.8%
0986Interval List IntersectionsGoMediumO(n)O(1)68.5%
0992Subarrays with K Different IntegersGoHardO(n)O(n)❤️50.9%
1004Max Consecutive Ones IIIGoMediumO(n)O(1)60.9%
1093Statistics from a Large SampleGoMediumO(n)O(1)48.8%
1234Replace the Substring for Balanced StringGoMedium34.6%
1658Minimum Operations to Reduce X to ZeroGoMedium33.3%
1695Maximum Erasure ValueGoMedium49.3%
——————————————————————-——-—————-—————————-————-————-

⬅️上一页

下一页➡️

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