/*
 * [15] 3Sum
 *
 * https://leetcode.com/problems/3sum
 *
 * Medium (21.56%)
 * Total Accepted:
 * Total Submissions:
 * Testcase Example:  '[-1,0,1,2,-1,-4]'
 *
 * Given an array S of n integers, are there elements a, b, c in S such that a
 * + b + c = 0? Find all unique triplets in the array which gives the sum of
 * zero.
 *
 * Note: The solution set must not contain duplicate triplets.
 *
 *
 * For example, given array S = [-1, 0, 1, 2, -1, -4],
 *
 * A solution set is:
 * [
 * ⁠ [-1, 0, 1],
 * ⁠ [-1, -1, 2]
 * ]
 */

三个数之和

转换为2个数之和

1.Map法

查找只需要O(1)

2.双指针法

很通用的一种方法 当为两个数 ,在[…]中找到两个数 a + b = target 若[…]没有排好序,先排序 然后两个指针分别从两边向中间集中 { if : a + b < target begin++ if : a + b > target end— } 通过这样的方式扫描完全部就可以得到解空间