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

Commit3985a99

Browse files
refactor 354
1 parentb6d18b8 commit3985a99

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
publicclass_354 {
19-
/**reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation*/
20-
publicintmaxEnvelopes(int[][]envelopes) {
21-
if (envelopes ==null ||envelopes.length ==0
19+
publicstaticclassSolution1 {
20+
/** reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation */
21+
publicintmaxEnvelopes(int[][]envelopes) {
22+
if (envelopes ==null ||envelopes.length ==0
2223
||envelopes[0].length ==0 ||envelopes[0].length !=2) {
23-
return0;
24-
}
25-
Arrays.sort(envelopes, (int[]a,int[]b) -> {
24+
return0;
25+
}
26+
Arrays.sort(envelopes, (int[]a,int[]b) -> {
2627
if (a[0] ==b[0]) {
2728
returnb[1] -a[1];
2829
}else {
2930
returna[0] -b[0];
3031
}
3132
}
32-
);
33-
int[]dp =newint[envelopes.length];
34-
intlen =0;
35-
for (int[]envelope :envelopes) {
36-
intindex =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 =newint[envelopes.length];
35+
intlen =0;
36+
for (int[]envelope :envelopes) {
37+
intindex =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+
returnlen;
4447
}
45-
returnlen;
4648
}
4749
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp