# 四数之和

<p>给定一个包含 <em>n</em> 个整数的数组 <code>nums</code> 和一个目标值 <code>target</code>，判断 <code>nums</code> 中是否存在四个元素 <em>a，</em><em>b，c</em> 和 <em>d</em> ，使得 <em>a</em> + <em>b</em> + <em>c</em> + <em>d</em> 的值与 <code>target</code> 相等？找出所有满足条件且不重复的四元组。</p><p><strong>注意：</strong>答案中不可以包含重复的四元组。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [1,0,-1,0,-2,2], target = 0<strong><br />输出：</strong>[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [], target = 0<strong><br />输出：</strong>[]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>0 <= nums.length <= 200</code></li>	<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>	<li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li></ul>

## template

```python
class Solution(object):
	def fourSum(self, nums, target):
		"""
		:type nums: List[int]
		:type target: int
		:rtype: List[List[int]]
		"""
		nums.sort()
		results = []
		N = len(nums)
		i = 0
		while i < N-3:
			if i > 0 and nums[i] == nums[i-1]:
				i += 1
				continue
			j = i+1
			while j < N-2:
				if j > i+1 and nums[j] == nums[j-1]:
					j += 1
					continue
				k = j+1
				l = N-1
				while k < l:
					if k > j+1 and nums[k] == nums[k-1]:
						k += 1
						continue
					while k < l and (target - nums[i] - nums[j] - nums[k] - nums[l]) < 0:
						l -= 1
					if k >= l:
						break
					if target == nums[i] + nums[j] + nums[k] + nums[l]:
						results.append([
							nums[i],
							nums[j],
							nums[k],
							nums[l]
						])
					k += 1
				j += 1
			i += 1
		return results
# %%
s = Solution()
print(s.fourSum(nums = [1,0,-1,0,-2,2], target = 0))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```