-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
143 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,43 @@ | ||
--- | ||
title: 16. 最接近的三数之和 | ||
problem_no: 16 | ||
date: 2022-09-18 | ||
description: | ||
timeline: false | ||
article: false | ||
category: | ||
- LeetCode | ||
--- | ||
# [16\. 3Sum Closest](https://leetcode.cn/problems/3sum-closest/) | ||
|
||
## [Description]((https://leetcode.cn/problems/3sum-closest/)) | ||
## Description | ||
|
||
Related Topics: [数组](https://leetcode.cn/tag/array/), [双指针](https://leetcode.cn/tag/two-pointers/), [排序](https://leetcode.cn/tag/sorting/) | ||
Difficulty: **中等** | ||
|
||
Related Topics: [Array](https://leetcode.cn/tag/https://leetcode.cn/tag/array//), [Two Pointers](https://leetcode.cn/tag/https://leetcode.cn/tag/two-pointers//), [Sorting](https://leetcode.cn/tag/https://leetcode.cn/tag/sorting//) | ||
|
||
给你一个长度为 `n` 的整数数组 `nums`和 一个目标值 `target`。请你从 `nums`中选出三个整数,使它们的和与 `target` 最接近。 | ||
|
||
返回这三个数的和。 | ||
Given an integer array `nums` of length `n` and an integer `target`, find three integers in `nums` such that the sum is closest to `target`. | ||
|
||
假定每组输入只存在恰好一个解。 | ||
Return _the sum of the three integers_. | ||
|
||
**示例 1:** | ||
You may assume that each input would have exactly one solution. | ||
|
||
**Example 1:** | ||
|
||
``` | ||
输入:nums = [-1,2,1,-4], target = 1 | ||
输出:2 | ||
解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。 | ||
Input: nums = [-1,2,1,-4], target = 1 | ||
Output: 2 | ||
Explanation: The sum that is closest to the target is 2\. (-1 + 2 + 1 = 2). | ||
``` | ||
|
||
**示例 2:** | ||
**Example 2:** | ||
|
||
``` | ||
输入:nums = [0,0,0], target = 1 | ||
输出:0 | ||
Input: nums = [0,0,0], target = 1 | ||
Output: 0 | ||
Explanation: The sum that is closest to the target is 0\. (0 + 0 + 0 = 0). | ||
``` | ||
|
||
**提示:** | ||
**Constraints:** | ||
|
||
* `3 <= nums.length <= 1000` | ||
* `3 <= nums.length <= 500` | ||
* `-1000 <= nums[i] <= 1000` | ||
* -10<sup>4</sup> <= target <= 10<sup>4</sup> | ||
|
||
|
||
## Solution | ||
|
||
Language: **C++** | ||
Language: **Go** | ||
|
||
@[code](@IOI/16-main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.