Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8dbd447

Browse files
refactor 1099
1 parent52cdd5b commit8dbd447

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
importjava.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
publicclass_1099 {
306
publicstaticclassSolution1 {
317
/**
328
* Time: O(n^2)
339
* Space: O(1)
34-
* */
10+
*/
3511
publicinttwoSumLessThanK(int[]A,intK) {
3612
intmaxSum =Integer.MIN_VALUE;
3713
for (inti =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
publicinttwoSumLessThanK(int[]A,intK) {
5430
Arrays.sort(A);
5531
intleft =0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp