class Solution:
    def threeSumClosest(self, nums: List[int], target: int) -> int:
        nums.sort()
        res = sum(nums[:3])
        for i in range(len(nums) -2):
            l, r = i+1, len(nums)-1
            while l<r:
                sumhere = nums[i] +nums[l]+nums[r]
                if abs(sumhere-target) < abs(res - target):
                    res = sumhere
                if sumhere > target:
                    r=r-1
                else:
                    l=l+1
        return res
