3 sum closest

3 sum 的变形题


3 sum closest_第1张图片

Solution1:

sort first, then iterate the array, fix one element,  using two pointer to calculate the sum for 3 elements, using absolute value to determine which is the closest result.

time: O(n^2), space: O(1)



3 sum closest_第2张图片

你可能感兴趣的:(3 sum closest)