Leetcode 16

在数组中找到三个数字使得其和与给定的target最接近。

1.将数组排序
2.使用两层循环,外层循环遍历first,内层循环寻找second和third
second初始化为first+1,third初始化为third-1。根据和与target的比较,移动这两个指针。
更新最接近的值

你可能感兴趣的:(Leetcode 16)