Package g0001_0100.s0016_3sum_closest
Class Solution
java.lang.Object
g0001_0100.s0016_3sum_closest.Solution
16 - 3Sum Closest.<p>Medium</p>
<p>Given an integer array <code>nums</code> of length <code>n</code> and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>.</p>
<p>Return <em>the sum of the three integers</em>.</p>
<p>You may assume that each input would have exactly one solution.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [-1,2,1,-4], target = 1</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [0,0,0], target = 1</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= nums.length <= 1000</code></li>
<li><code>-1000 <= nums[i] <= 1000</code></li>
<li><code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
threeSumClosest
public int threeSumClosest(int[] nums, int target)
-