3Sum Closest

Given an integer array and a target integer, find three integers in the array such that their sum is closest to the target. Return the sum of these three integers. Assume there is exactly one solution.

Constraints

  • 3 <= nums.length <= 500
  • -1000 <= nums[i] <= 1000
  • -10^4 <= target <= 10^4
Saving… · 2 lines
class Solution:
def threeSumClosest(self, nums: List[int], target: int) -> int:
Console

Click Run to execute sample tests.