![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
同向双指针
文章平均质量分 72
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Given an array of integersnumsand an integerlimit, return the size of the longestnon-emptysubarray such that the absolute difference between any two elements of this subarray is less than or equal tolimit.Example 1:Input: nums = [8,2,4,7], limit...原创 2022-03-23 01:11:59 · 171 阅读 · 0 评论 -
Max Consecutive Ones II
Given a binary arraynums, returnthe maximum number of consecutive1's in the array if you can flip at most one0.Example 1:Input: nums = [1,0,1,1,0]Output: 4Explanation: Flip the first zero will get the maximum number of consecutive 1s. After flip...原创 2022-03-20 11:07:30 · 297 阅读 · 0 评论 -
Move Zeroes
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of the array.Example 1:Input: nums = [0,1,0,3,12]Output: [1,3,12,0,0]原创 2022-02-20 13:57:09 · 186 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Given an integer arraynumssorted innon-decreasing order, remove the duplicatesin-placesuch that each unique element appears onlyonce. Therelative orderof the elements should be kept thesame.Since it is impossible to change the length of the arra...原创 2022-02-11 13:21:04 · 115 阅读 · 0 评论 -
Minimum Swaps to Group All 1‘s Together II
Aswapis defined as taking twodistinctpositions in an array and swapping the values in them.Acirculararray is defined as an array where we consider thefirstelement and thelastelement to beadjacent.Given abinarycirculararraynums, returnth...原创 2022-01-09 14:26:34 · 331 阅读 · 0 评论 -
Last Substring in Lexicographical Order
Given a strings, return the last substring ofsin lexicographical order.Example 1:Input: "abab"Output: "bab"Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".Example 2...原创 2020-09-05 08:10:56 · 240 阅读 · 0 评论 -
Fruit Into Baskets
In a row of trees, thei-th treeproducesfruit with typetree[i].Youstart at any treeof your choice, then repeatedly perform the following steps:Add one piece of fruit from this tree to your baskets. If you cannot, stop. Move to the next tree to t...原创 2020-06-20 05:51:39 · 217 阅读 · 0 评论 -
Maximum Points You Can Obtain from Cards
There are several cardsarranged in a row, and each card has an associated number of pointsThe points are given in the integer arraycardPoints.In one step, you can take one card from the beginning or from the end of the row. You have to take exactlyk...原创 2020-06-19 11:32:17 · 453 阅读 · 0 评论 -
Longest Repeating Character Replacement
Given a stringsthat consists of only uppercase English letters, you can perform at mostkoperations on that string.In one operation, you can chooseanycharacter of the string and change it to any other uppercase English character.Find the length of...原创 2020-06-17 11:43:28 · 189 阅读 · 0 评论 -
Maximum Number of Vowels in a Substring of Given Length
Given a stringsand an integerk.Returnthe maximum number of vowel lettersin any substring ofswithlengthk.Vowel lettersinEnglish are(a, e, i, o, u).Example 1:Input: s = "abciiidef", k = 3Output: 3Explanation: The substring "iii" con...原创 2020-05-25 04:52:10 · 190 阅读 · 0 评论 -
Substrings of size K with K distinct chars
Given a stringsand an intk, return an int representing the number of substrings (not unique) ofswith exactlykdistinct characters. If the given string doesn't havekdistinct characters, return ...原创 2020-04-27 11:44:10 · 291 阅读 · 0 评论 -
Subarrays with K Different Integers
Given an arrayAof positive integers, call a (contiguous, not necessarily distinct) subarray ofAgoodif the number of different integers in that subarray is exactlyK.(For example,[1,2,3,1,2]ha...原创 2020-04-27 11:54:17 · 372 阅读 · 0 评论 -
Count Number of Nice Subarrays
Given an array of integersnumsand an integerk. Asubarrayis calledniceif there arekodd numbers on it.Return the number ofnicesub-arrays.Example 1:Input: nums = [1,1,2,1,1], k = 3Output: 2Explanation: The only sub-arrays with 3 odd number...原创 2020-05-17 08:37:27 · 266 阅读 · 0 评论 -
Max Consecutive Ones III
Given an arrayAof 0s and 1s, we may change up toKvalues from 0 to 1.Return the length of the longest (contiguous) subarray that contains only 1s.Example 1:Input: A = [1,1,1,0,0,0,1,1,1,1,0], K = 2Output: 6Explanation: [1,1,1,0,0,1,1,1,1,1,1]...原创 2020-05-17 08:23:05 · 193 阅读 · 0 评论 -
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Given anarray of integersnumsand anintegerlimit, return the size of the longest continuous subarray such that the absolute difference between any two elements is less than or equal tolimit.In ...原创 2020-05-04 00:38:24 · 374 阅读 · 0 评论 -
Find All Anagrams in a String
Given a stringsand anon-emptystringp, find all the start indices ofp's anagrams ins.Strings consists of lowercase English letters only and the length of both stringssandpwill not be large...原创 2019-01-13 12:31:16 · 221 阅读 · 0 评论 -
Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3,1,...原创 2016-09-06 08:58:18 · 466 阅读 · 0 评论 -
Two Sum Less Than K
Given an arrayAof integers andintegerK, return the maximumSsuch that there existsi < jwithA[i] + A[j] = SandS < K. If noi, jexist satisfying this equation, return -1.Example 1:...原创 2020-04-16 12:21:11 · 495 阅读 · 0 评论 -
Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].Credits:Special thanks to@jianchao.li.fighter原创 2016-09-08 05:16:26 · 221 阅读 · 0 评论 -
Find the Duplicate Number
Given an arraynumscontainingn + 1integers where each integer is between1andn(inclusive), guarantee that at least one duplicate number must exist. Assume that there is only one duplicate number...原创 2016-08-12 07:09:04 · 378 阅读 · 0 评论 -
Longest Substring with At Most Two Distinct Characters
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example,Given s = “eceba”,T is "ece" which its length is 3.思路:同向双指针,跟Longest Substri...原创 2016-09-04 14:48:57 · 396 阅读 · 0 评论 -
Longest Substring with At Most K Distinct Characters
Given a string, find the length of the longest substring T that contains at mostk distinct characters.For example,Given s = “eceba” and k = 2,T is "ece" which its length is 3.思路:跟 Longest Su...原创 2016-09-05 03:23:38 · 667 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For ...原创 2014-12-09 10:21:20 · 656 阅读 · 0 评论 -
Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".No...原创 2014-12-18 13:04:24 · 673 阅读 · 0 评论 -
同向双指针算法题总结
同向双指针是经常考的一种题型;什么时候用?发现题目,两个指针,只要固定一个,另外一个扫描,总是有坏坏坏,突然变好,不再回来或者好好好,忽然变坏,不再回来,那么就是同向双指针算法,基本上都是O(n)的算法复杂度;写程序注意的点:固定i,i是主指针每次走一步,写for循环,j是辅指针,写while循环,每次可能走N步;Minimum Size Subarray Sum给定一...原创 2020-01-07 12:24:15 · 2142 阅读 · 0 评论