Skip to content

Commit 3985a99

Browse files
refactor 354
1 parent b6d18b8 commit 3985a99

File tree

1 file changed

+20
-18
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+20
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,34 @@
1616
1717
*/
1818
public class _354 {
19-
/**reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation*/
20-
public int maxEnvelopes(int[][] envelopes) {
21-
if (envelopes == null || envelopes.length == 0
19+
public static class Solution1 {
20+
/** reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation */
21+
public int maxEnvelopes(int[][] envelopes) {
22+
if (envelopes == null || envelopes.length == 0
2223
|| envelopes[0].length == 0 || envelopes[0].length != 2) {
23-
return 0;
24-
}
25-
Arrays.sort(envelopes, (int[] a, int[] b) -> {
24+
return 0;
25+
}
26+
Arrays.sort(envelopes, (int[] a, int[] b) -> {
2627
if (a[0] == b[0]) {
2728
return b[1] - a[1];
2829
} else {
2930
return a[0] - b[0];
3031
}
3132
}
32-
);
33-
int[] dp = new int[envelopes.length];
34-
int len = 0;
35-
for (int[] envelope : envelopes) {
36-
int index = Arrays.binarySearch(dp, 0, len, envelope[1]);
37-
if (index < 0) {
38-
index = -(index + 1);
39-
}
40-
dp[index] = envelope[1];
41-
if (index == len) {
42-
len++;
33+
);
34+
int[] dp = new int[envelopes.length];
35+
int len = 0;
36+
for (int[] envelope : envelopes) {
37+
int index = Arrays.binarySearch(dp, 0, len, envelope[1]);
38+
if (index < 0) {
39+
index = -(index + 1);
40+
}
41+
dp[index] = envelope[1];
42+
if (index == len) {
43+
len++;
44+
}
4345
}
46+
return len;
4447
}
45-
return len;
4648
}
4749
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy