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
0011Container With Most WaterGoMediumO(n)O(1)53.9%
00153SumGoMediumO(n^2)O(n)❤️31.1%
00163Sum ClosestGoMediumO(n^2)O(1)❤️47.1%
00184SumGoMediumO(n^3)O(n^2)❤️37.3%
0019Remove Nth Node From End of ListGoMediumO(n)O(1)38.3%
0026Remove Duplicates from Sorted ArrayGoEasyO(n)O(1)48.9%
0027Remove ElementGoEasyO(n)O(1)51.2%
0028Implement strStr()GoEasyO(n)O(1)35.9%
0031Next PermutationGoMedium36.4%
0042Trapping Rain WaterGoHardO(n)O(1)❤️56.5%
0061Rotate ListGoMediumO(n)O(1)34.9%
0075Sort ColorsGoMediumO(n)O(1)❤️54.8%
0080Remove Duplicates from Sorted Array IIGoMediumO(n)O(150.5%
0082Remove Duplicates from Sorted List IIGoMedium44.3%
0086Partition ListGoMediumO(n)O(1)❤️47.9%
0088Merge Sorted ArrayGoEasyO(n)O(1)❤️43.9%
0125Valid PalindromeGoEasyO(n)O(1)41.7%
0141Linked List CycleGoEasyO(n)O(1)❤️45.9%
0142Linked List Cycle IIGoMediumO(n)O(1)❤️44.2%
0143Reorder ListGoMedium47.9%
0148Sort ListGoMedium52.1%
0151Reverse Words in a StringGoMedium28.5%
0160Intersection of Two Linked ListsGoEasy49.9%
0167Two Sum II - Input Array Is SortedGoMediumO(n)O(1)58.7%
0189Rotate ArrayGoMedium38.6%
0202Happy NumberGoEasy53.2%
0234Palindrome Linked ListGoEasyO(n)O(1)46.6%
0283Move ZeroesGoEasyO(n)O(1)60.6%
0287Find the Duplicate NumberGoMediumO(n)O(1)❤️58.8%
0344Reverse StringGoEasyO(n)O(1)74.9%
0345Reverse Vowels of a StringGoEasyO(n)O(1)47.0%
0349Intersection of Two ArraysGoEasyO(n)O(n)69.1%
0350Intersection of Two Arrays IIGoEasyO(n)O(n)54.9%
0392Is SubsequenceGoEasy51.0%
0457Circular Array LoopGoMedium31.7%
0475HeatersGoMedium35.3%
0524Longest Word in Dictionary through DeletingGoMediumO(n)O(1)50.9%
0532K-diff Pairs in an ArrayGoMediumO(n)O(n)40.1%
0541Reverse String IIGoEasy50.2%
0557Reverse Words in a String IIIGoEasy78.7%
0567Permutation in StringGoMediumO(n)O(1)❤️44.7%
0581Shortest Unsorted Continuous SubarrayGoMedium35.9%
0611Valid Triangle NumberGoMedium49.8%
0633Sum of Square NumbersGoMedium34.7%
0653Two Sum IV - Input is a BSTGoEasy58.8%
0658Find K Closest ElementsGoMedium44.5%
0696Count Binary SubstringsGoEasy64.9%
0719Find K-th Smallest Pair DistanceGoHard35.1%
0763Partition LabelsGoMediumO(n)O(1)❤️79.6%
0795Number of Subarrays with Bounded MaximumGoMedium52.4%
0821Shortest Distance to a CharacterGoEasy71.0%
0825Friends Of Appropriate AgesGoMedium46.0%
0826Most Profit Assigning WorkGoMediumO(n log n)O(n)42.1%
0832Flipping an ImageGoEasy79.7%
0838Push DominoesGoMediumO(n)O(n)52.3%
0844Backspace String CompareGoEasyO(n)O(n)48.0%
0845Longest Mountain in ArrayGoMediumO(n)O(1)39.8%
0876Middle of the Linked ListGoEasy72.6%
0881Boats to Save PeopleGoMediumO(n log n)O(1)52.5%
0922Sort Array By Parity IIGoEasy70.6%
09233Sum With MultiplicityGoMediumO(n^2)O(n)45.4%
0925Long Pressed NameGoEasyO(n)O(1)34.6%
0942DI String MatchGoEasy75.9%
0969Pancake SortingGoMedium69.7%
0977Squares of a Sorted ArrayGoEasyO(n)O(1)71.6%
0986Interval List IntersectionsGoMediumO(n)O(1)71.1%
1040Moving Stones Until Consecutive IIGoMedium55.6%
1048Longest String ChainGoMedium57.8%
1089Duplicate ZerosGoEasy51.1%
1093Statistics from a Large SampleGoMediumO(n)O(1)45.8%
1332Remove Palindromic SubsequencesGoEasy69.6%
1385Find the Distance Value Between Two ArraysGoEasy65.9%
1679Max Number of K-Sum PairsGoMedium57.7%
1721Swapping Nodes in a Linked ListGoMedium68.4%
1877Minimize Maximum Pair Sum in ArrayGoMedium80.7%
——————————————————————-——-—————-—————————-————-————-

⬅️上一页

下一页➡️

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