双指针类型题目的处理对象往往是线性表(例如数组、链表、字符串等),这种类型的题目在LeetCode中是比较普遍的,但难道往往不大。本文并不打算覆盖所有可能的子类型,仅抛砖引玉地讨论几道有一定代表性(同时也可能不太容易想到解法)的问题。
概括来说,双指针题目可以有如下图所示的四种类型(原图引自博文):
题目15:3Sum
Given an array nums
of n integers, are there elements a, b, c in nums
such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Notice that the solution set must not co