Skip to content

Commit 1b727d3

Browse files
refactor 354
1 parent d42b438 commit 1b727d3

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
import java.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
public class _354 {
196
public static class Solution1 {
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
public int maxEnvelopes(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
return 0;
2514
}
2615
Arrays.sort(envelopes, (int[] a, int[] b) -> {
27-
if (a[0] == b[0]) {
28-
return b[1] - a[1];
29-
} else {
30-
return a[0] - b[0];
16+
if (a[0] == b[0]) {
17+
return b[1] - a[1];
18+
} else {
19+
return a[0] - b[0];
20+
}
3121
}
32-
}
3322
);
3423
int[] dp = new int[envelopes.length];
3524
int len = 0;

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