Two Pointers

(1)两个 pointers 从头往后走:

绝大多数的 linked list 的题目都涉及到这个操作,当然还有array。这类题目很多时候又可以称为 sliding window。

题目归类:

lc28: Implement strStr()

lc3: Longest Substring Without Repeating Characters

lc76: Minimum Window Substring

lc26 & lc80: Remove Duplicates from Sorted Array & II

lc83 & lc82: Remove Duplicates from Sorted List & II

lc27: Remove Element

lc19: Remove Nth Node From End of List

lc92: Reverse Linked list II

lc61: Rotate List

lc30: Substring with Concatenation of All Words

lc20: Swap Nodes in Pairs

(2) 两个pointers从两头往中间走:

一般面试出现的的都是 singly linked list, 因此这类题主要是array题。

题目分类:

lc1: Two Sum

lc15: 3Sum

lc16: 3Sum Closest

lc18: 4Sum

lc11: Container With Most Water

lc75: Sort Colors

lc42: Trapping Rain Water

(3) 两个pointers控制两个不同的数组或链表:

一般出现在跟merge相关的题目上。

题目分类:

lc67: Add Binary

lc2: Add Two Numbers

lc88: Merge Sorted Array

lc21: Merge Two Sorted Lists

lc43: Multiply Strings

lc86: Partition List

Last updated