<jupyter_start><jupyter_text>Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.Example:Given array nums = [-1, 2, 1, -4], and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).<jupyter_code>nums=[1,2,4,8,16,32,64,128] #ans 82
target=82

def threeSumClosest(nums,target):
    nums.sort()
    res=0
    dif=float('inf')

    for i in range(len(nums)-2):
        if i>0 and nums[i]==nums[i-1]:
            continue

        l , r = i+1 , len(nums)-1
        while l<r:
            sums=nums[i]+nums[l]+nums[r]
            if target==sums:
                return sums
            if abs(target-sums) < dif:
                res=sums
                dif=abs(target-sums)
            if sums < target:
                l+=1
            else:
                r-=1
    return res
                
        
threeSumClosest(nums,target)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10931558935361217, 'fraction_numerical': 0.03326996197718631, 'mean_word_length': 1.949579831932773, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '508976', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 379, 'n_tokens_neox': 350, 'n_words': 106, 'path': '16. 3Sum Closest.ipynb', 'repo_name': 'kkoo1122/Leetcode_Practice', 'size': '1052'}