Java | Leetcode Java题解之第16题最接近的三数之和
题目:
题解:
class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int n = nums.length; int best = 10000000; // 枚举 a for (int i = 0; i 0 && nums[i] == nums[i - 1]) { continue; } // 使用双指针枚举 b 和 c int j = i + 1, k = n - 1; while (j target) { // 如果和大于 target,移动 c 对应的指针 int k0 = k - 1; // 移动到下一个不相等的元素 while (j
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。