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

Commit1b727d3

Browse files
refactor 354
1 parentd42b438 commit1b727d3

File tree

1 file changed

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

1 file changed

+9
-20
lines changed

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,23 @@
22

33
importjava.util.Arrays;
44

5-
/**
6-
* 354. Russian Doll Envelopes
7-
*
8-
* You have a number of envelopes with widths and heights given as a pair of integers (w, h).
9-
* One envelope can fit into another if and only if both the width and height of one envelope is greater than
10-
* the width and height of the other envelope.
11-
12-
What is the maximum number of envelopes can you Russian doll? (put one inside other)
13-
14-
Example:
15-
Given envelopes = [[5,4],[6,4],[6,7],[2,3]], the maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).
16-
17-
*/
185
publicclass_354 {
196
publicstaticclassSolution1 {
20-
/** reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation */
7+
/**
8+
* reference: https://discuss.leetcode.com/topic/47469/java-nlogn-solution-with-explanation
9+
*/
2110
publicintmaxEnvelopes(int[][]envelopes) {
2211
if (envelopes ==null ||envelopes.length ==0
23-
||envelopes[0].length ==0 ||envelopes[0].length !=2) {
12+
||envelopes[0].length ==0 ||envelopes[0].length !=2) {
2413
return0;
2514
}
2615
Arrays.sort(envelopes, (int[]a,int[]b) -> {
27-
if (a[0] ==b[0]) {
28-
returnb[1] -a[1];
29-
}else {
30-
returna[0] -b[0];
16+
if (a[0] ==b[0]) {
17+
returnb[1] -a[1];
18+
}else {
19+
returna[0] -b[0];
20+
}
3121
}
32-
}
3322
);
3423
int[]dp =newint[envelopes.length];
3524
intlen =0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp