We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 07dafed commit 8149908Copy full SHA for 8149908
src/main/java/com/fishercoder/solutions/_16.java
@@ -15,9 +15,6 @@ public class _16 {
15
16
public static class Solution1 {
17
public int threeSumClosest(int[] nums, int target) {
18
- if (nums == null || nums.length == 0) {
19
- return 0;
20
- }
21
Arrays.sort(nums);
22
int len = nums.length;
23
if (len < 3) {
@@ -28,9 +25,9 @@ public int threeSumClosest(int[] nums, int target) {
28
25
return sum;
29
26
}
30
27
int sum = nums[0] + nums[1] + nums[2];
31
- for (int i = 0; i < nums.length - 2; i++) {
+ for (int i = 0; i < len - 2; i++) {
32
int left = i + 1;
33
- int right = nums.length - 1;
+ int right = len - 1;
34
while (left < right) {
35
int thisSum = nums[i] + nums[left] + nums[right];
36
if (Math.abs(target - thisSum) < Math.abs(target - sum)) {
0 commit comments