Tap here to switch tabs
Problem
Submissions

Problem: 3Sum Closest

3Sum Closest asks you to choose three values from an integer array and return their sum, selecting the unique sum whose distance from a target is smallest. Values may be negative.

Statement

Given an integer array nums and an integer target, return the sum of three integers in nums whose value is closest to target.

You may assume that each input has exactly one solution.

Note: The solution is guaranteed to be unique.

Constraints:

  • 3≤3 \leq nums.length ≤500\leq 500

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000

  • −104≤-10^4 \leq target ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: 3Sum Closest

3Sum Closest asks you to choose three values from an integer array and return their sum, selecting the unique sum whose distance from a target is smallest. Values may be negative.

Statement

Given an integer array nums and an integer target, return the sum of three integers in nums whose value is closest to target.

You may assume that each input has exactly one solution.

Note: The solution is guaranteed to be unique.

Constraints:

  • 3≤3 \leq nums.length ≤500\leq 500

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000

  • −104≤-10^4 \leq target ≤104\leq 10^4