Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8dbd447

Browse files
refactor 1099
1 parent 52cdd5b commit 8dbd447

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,12 @@
22

33
import java.util.Arrays;
44

5-
/**
6-
* 1099. Two Sum Less Than K
7-
*
8-
* Given an array A of integers and integer K,
9-
* return the maximum S such that there exists i < j with A[i] + A[j] = S and S < K.
10-
* If no i, j exist satisfying this equation, return -1.
11-
*
12-
* Example 1:
13-
* Input: A = [34,23,1,24,75,33,54,8], K = 60
14-
* Output: 58
15-
* Explanation:
16-
* We can use 34 and 24 to sum 58 which is less than 60.
17-
*
18-
* Example 2:
19-
* Input: A = [10,20,30], K = 15
20-
* Output: -1
21-
* Explanation:
22-
* In this case it's not possible to get a pair sum less that 15.
23-
*
24-
* Note:
25-
* 1 <= A.length <= 100
26-
* 1 <= A[i] <= 1000
27-
* 1 <= K <= 2000
28-
* */
295
public class _1099 {
306
public static class Solution1 {
317
/**
328
* Time: O(n^2)
339
* Space: O(1)
34-
* */
10+
*/
3511
public int twoSumLessThanK(int[] A, int K) {
3612
int maxSum = Integer.MIN_VALUE;
3713
for (int i = 0; i < A.length - 1; i++) {
@@ -49,7 +25,7 @@ public static class Solution2 {
4925
/**
5026
* Time: O(nlogn)
5127
* Space: O(1)
52-
* */
28+
*/
5329
public int twoSumLessThanK(int[] A, int K) {
5430
Arrays.sort(A);
5531
int left = 0;

0 commit comments

Comments
 (0)