```
class Solution(object):
def threeSumClosest(self, nums, target):
res = float('inf')
nums.sort()
for i in xrange(len(nums)-2):
l, r = i+1, len(nums)-1
while l < r:
s = nums[i] + nums[l] + nums[r] - target
res = min(s,res,key=abs)
l+= s<=0; r-= s>0
return res+target
```