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题。
(3) 两个pointers控制两个不同的数组或链表:
一般出现在跟merge相关的题目上。
Last updated
Was this helpful?