Given an array S of n integers, are there elements x, y, z in S such that x + y + z = 0? Find all unique triplets in the array which gives the sum of zero.
Note:
- Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ≤ c)
- The solution set must not contain duplicate triplets.
一個(gè)重要的優(yōu)化就是如果上個(gè)數(shù)已經(jīng)求過集合了 例如[-1 -1 0 2 2]已經(jīng)包含了[-1 0 2 2] 當(dāng)然也包含了 [-1 0 2]集合的。