Skip to content

Commit 8149908

Browse files
[N-0] refactor 16
1 parent 07dafed commit 8149908

File tree

1 file changed

+2
-5
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-5
lines changed

src/main/java/com/fishercoder/solutions/_16.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public class _16 {
1515

1616
public static class Solution1 {
1717
public int threeSumClosest(int[] nums, int target) {
18-
if (nums == null || nums.length == 0) {
19-
return 0;
20-
}
2118
Arrays.sort(nums);
2219
int len = nums.length;
2320
if (len < 3) {
@@ -28,9 +25,9 @@ public int threeSumClosest(int[] nums, int target) {
2825
return sum;
2926
}
3027
int sum = nums[0] + nums[1] + nums[2];
31-
for (int i = 0; i < nums.length - 2; i++) {
28+
for (int i = 0; i < len - 2; i++) {
3229
int left = i + 1;
33-
int right = nums.length - 1;
30+
int right = len - 1;
3431
while (left < right) {
3532
int thisSum = nums[i] + nums[left] + nums[right];
3633
if (Math.abs(target - thisSum) < Math.abs(target - sum)) {

0 commit comments

Comments
 (0)