You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Java/3Sum Smaller.java
+5-7Lines changed: 5 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@
8
8
9
9
```
10
10
/*
11
-
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.
11
+
Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n
12
+
that satisfy the condition nums[i] + nums[j] + nums[k] < target.
12
13
13
14
For example, given nums = [-2, 0, 1, 3], and target = 2.
14
15
@@ -38,13 +39,10 @@ public int threeSumSmaller(int[] nums, int target) {
38
39
}
39
40
Arrays.sort(nums);
40
41
intcount = 0;
41
-
intstart, end;
42
-
for (inti = 0; i < nums.length - 2; i++) {
43
-
intfirstNum = nums[i];
44
-
start = i + 1;
45
-
end = nums.length - 1;
42
+
for (inti = 0; i < nums.length - 2; i++) { // first num, num[i] is the fixed item
43
+
intstart = i + 1, end = nums.length - 1; // move start, end
0 commit comments