File tree 2 files changed +10
-10
lines changed
src/com/blankj/medium/_016
2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -24,17 +24,17 @@ public class Solution {
24
24
Arrays . sort(nums);
25
25
int len = nums. length - 2 ;
26
26
for (int i = 0 ; i < len; i++ ) {
27
- int st = i + 1 , end = nums. length - 1 ;
28
- while (st < end ) {
29
- int sum = nums[i] + nums[st ] + nums[end ];
27
+ int left = i + 1 , right = nums. length - 1 ;
28
+ while (left < right ) {
29
+ int sum = nums[i] + nums[left ] + nums[right ];
30
30
int curDelta = Math . abs(sum - target);
31
31
if (curDelta == 0 ) return sum;
32
32
if (curDelta < delta) {
33
33
delta = curDelta;
34
34
res = sum;
35
35
}
36
- if (sum > target) -- end ;
37
- else ++ st ;
36
+ if (sum > target) -- right ;
37
+ else ++ left ;
38
38
}
39
39
}
40
40
return res;
Original file line number Diff line number Diff line change @@ -16,17 +16,17 @@ public int threeSumClosest(int[] nums, int target) {
16
16
Arrays .sort (nums );
17
17
int len = nums .length - 2 ;
18
18
for (int i = 0 ; i < len ; i ++) {
19
- int st = i + 1 , end = nums .length - 1 ;
20
- while (st < end ) {
21
- int sum = nums [i ] + nums [st ] + nums [end ];
19
+ int left = i + 1 , right = nums .length - 1 ;
20
+ while (left < right ) {
21
+ int sum = nums [i ] + nums [left ] + nums [right ];
22
22
int curDelta = Math .abs (sum - target );
23
23
if (curDelta == 0 ) return sum ;
24
24
if (curDelta < delta ) {
25
25
delta = curDelta ;
26
26
res = sum ;
27
27
}
28
- if (sum > target ) --end ;
29
- else ++st ;
28
+ if (sum > target ) --right ;
29
+ else ++left ;
30
30
}
31
31
}
32
32
return res ;
You can’t perform that action at this time.
0 commit comments