您的位置:首页 > 其它

Leetcode 16[medium]--3Sum Closest

2018-02-06 08:15 369 查看
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.



思路:仍然是双支针法,先将S sort ,将元素从大到小排列。一个for 循环将三个integers中的第一个逐一定位。用另外两个指针指向后两个数。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: