|
| 1 | +<h2><ahref="https://leetcode.com/problems/4sum/">18. 4Sum</a></h2><h3>Medium</h3><hr><p>Given an array <code>nums</code> of <code>n</code> integers, return <em>an array of all the <strong>unique</strong> quadruplets</em> <code>[nums[a], nums[b], nums[c], nums[d]]</code> such that:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | +<li><code>0 <= a, b, c, d < n</code></li> |
| 5 | +<li><code>a</code>, <code>b</code>, <code>c</code>, and <code>d</code> are <strong>distinct</strong>.</li> |
| 6 | +<li><code>nums[a] + nums[b] + nums[c] + nums[d] == target</code></li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>You may return the answer in <strong>any order</strong>.</p> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strongclass="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> nums = [1,0,-1,0,-2,2], target = 0 |
| 16 | +<strong>Output:</strong> [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]] |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strongclass="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> nums = [2,2,2,2,2], target = 8 |
| 23 | +<strong>Output:</strong> [[2,2,2,2]] |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | +<li><code>1 <= nums.length <= 200</code></li> |
| 31 | +<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li> |
| 32 | +<li><code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code></li> |
| 33 | +</ul> |