1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最接近的三数之和 [3sum-closest].html

33 lines
962 B
HTML
Raw Normal View History

2022-03-27 20:56:26 +08:00
<p>给你一个长度为 <code>n</code> 的整数数组&nbsp;<code>nums</code><em>&nbsp;</em>和 一个目标值&nbsp;<code>target</code>。请你从 <code>nums</code><em> </em>中选出三个整数,使它们的和与&nbsp;<code>target</code>&nbsp;最接近。</p>
<p>返回这三个数的和。</p>
<p>假定每组输入只存在恰好一个解。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [-1,2,1,-4], target = 1
<strong>输出:</strong>2
<strong>解释:</strong>与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [0,0,0], target = 1
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= nums.length &lt;= 1000</code></li>
<li><code>-1000 &lt;= nums[i] &lt;= 1000</code></li>
<li><code>-10<sup>4</sup> &lt;= target &lt;= 10<sup>4</sup></code></li>
</ul>