@@ -8,12 +8,12 @@ public static class Solution1 {
8
8
* Time: O(n^2)
9
9
* Space: O(1)
10
10
*/
11
- public int twoSumLessThanK (int [] A , int K ) {
11
+ public int twoSumLessThanK (int [] nums , int k ) {
12
12
int maxSum = Integer .MIN_VALUE ;
13
- for (int i = 0 ; i < A .length - 1 ; i ++) {
14
- for (int j = i + 1 ; j < A .length ; j ++) {
15
- if (A [i ] + A [j ] < K ) {
16
- maxSum = Math .max (maxSum , A [i ] + A [j ]);
13
+ for (int i = 0 ; i < nums .length - 1 ; i ++) {
14
+ for (int j = i + 1 ; j < nums .length ; j ++) {
15
+ if (nums [i ] + nums [j ] < k ) {
16
+ maxSum = Math .max (maxSum , nums [i ] + nums [j ]);
17
17
}
18
18
}
19
19
}
@@ -26,16 +26,16 @@ public static class Solution2 {
26
26
* Time: O(nlogn)
27
27
* Space: O(1)
28
28
*/
29
- public int twoSumLessThanK (int [] A , int K ) {
30
- Arrays .sort (A );
29
+ public int twoSumLessThanK (int [] nums , int k ) {
30
+ Arrays .sort (nums );
31
31
int left = 0 ;
32
- int right = A .length - 1 ;
32
+ int right = nums .length - 1 ;
33
33
int sum = Integer .MIN_VALUE ;
34
34
while (left < right ) {
35
- int newSum = A [left ] + A [right ];
36
- if (newSum < K && newSum > sum ) {
35
+ int newSum = nums [left ] + nums [right ];
36
+ if (newSum < k && newSum > sum ) {
37
37
sum = newSum ;
38
- } else if (newSum >= K ) {
38
+ } else if (newSum >= k ) {
39
39
right --;
40
40
} else {
41
41
left ++;
0 commit comments