# 三数之和

<p>给你一个包含 <code>n</code> 个整数的数组 <code>nums</code>，判断 <code>nums</code> 中是否存在三个元素 <em>a，b，c ，</em>使得 <em>a + b + c = </em>0 ？请你找出所有和为 <code>0</code> 且不重复的三元组。</p><p><strong>注意：</strong>答案中不可以包含重复的三元组。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [-1,0,1,2,-1,-4]<strong><br />输出：</strong>[[-1,-1,2],[-1,0,1]]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = []<strong><br />输出：</strong>[]</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>nums = [0]<strong><br />输出：</strong>[]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>0 <= nums.length <= 3000</code></li>	<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li></ul>

## template

```java
class Solution {
	public List<List<Integer>> threeSum(int[] nums) {
		Arrays.sort(nums);
		List<List<Integer>> result = new ArrayList<>();
		int cur, left, right;
		cur = 0;
		while (cur < nums.length) {
			if (nums[cur] > 0)
				break;
			left = cur + 1;
			right = nums.length - 1;
			while (left < right) {
				int n = nums[cur] + nums[left] + nums[right];
				if (n == 0) {
					List<Integer> r = new ArrayList<Integer>();
					r.add(nums[cur]);
					r.add(nums[left]);
					r.add(nums[right]);
					result.add(r);
					int t = left + 1;
					while (t < right && nums[t] == nums[left])
						t++;
					left = t;
					t = right - 1;
					while (t > left && nums[t] == nums[right])
						t--;
					right = t;
				} else if (n > 0) {
					int t = right - 1;
					while (t > left && nums[t] == nums[right])
						t--;
					right = t;
				} else {
					int t = left + 1;
					while (t < right && nums[t] == nums[left])
						t++;
					left = t;
				}
			}
			int t = cur + 1;
			while (t < nums.length && nums[t] == nums[cur])
				t++;
			cur = t;
		}
		return result;
	}
}
```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```