演算法學習100天——18 雙指標題型分類
阿新 • • 發佈:2022-04-01
花了一個多禮拜,把多執行緒再學習了一遍
繼續回來學演算法
刷題是基於github上CS-Notes來的
在此基礎上,我用自己的理解將雙指標分成了以下三類
-
左右型雙指標
兩個指標在一個數組左右兩邊
- 有序陣列中找兩數和為targethttps://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/description/
- 給定一個整數target,找到兩個數的平方和為targethttps://leetcode-cn.com/problems/sum-of-square-numbers/description/
- 反轉單詞中的母音字母https://leetcode-cn.com/problems/reverse-vowels-of-a-string/description/
- 判斷一個字串是否為迴文串,字串刪去一個字元滿足的話,也算是,如“abca”
其實就是求(str, i , j) || (str, i + 1 , j) || (str, i , j - 1) https://leetcode-cn.com/problems/valid-palindrome-ii/description/
-
平行型雙指標
兩個指標在不同的兩個陣列/連結串列上
- 歸併兩個字串/陣列/連結串列https://leetcode-cn.com/problems/merge-sorted-array/description/
- 找出字串陣列中,最長子序列https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting/description/
-
快慢型雙指標
兩個指標在同一個方向,但是一個移動速度快,一個速度慢
- 判斷一個連結串列是否有環https://leetcode-cn.com/problems/linked-list-cycle/description/