forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
29 lines (29 loc) · 859 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public int maxHeight(int[][] cuboids) {
for (int[] c : cuboids) {
Arrays.sort(c);
}
Arrays.sort(cuboids, (a, b) -> {
if (a[0] != b[0]) {
return a[0] - b[0];
}
if (a[1] != b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
int n = cuboids.length;
int[] dp = new int[n];
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (cuboids[j][1] <= cuboids[i][1] && cuboids[j][2] <= cuboids[i][2]) {
dp[i] = Math.max(dp[i], dp[j]);
}
}
dp[i] += cuboids[i][2];
ans = Math.max(ans, dp[i]);
}
return ans;
}
}