import math
from typing import List
classSolution:defthreeSumClosest(self, nums: List[int], target:int)->int:
res = math.inf
n =len(nums)
nums.sort()for first inrange(n -2):if first >0and nums[first]== nums[first -1]:continue
second = first +1
third = n -1while second < third:
s = nums[first]+ nums[second]+ nums[third]ifabs(s - target)<abs(res - target):
res = s
if s > target:
third -=1elif s < target:
second +=1else:return target
return res
if __name__ =="__main__":
s = Solution()
nums =[0,0,0]print(s.threeSum(nums,1))