File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[][] } cuboids
3
+ * @return {number }
4
+ */
5
+ var maxHeight = function ( cuboids ) {
6
+ let n = cuboids . length
7
+ for ( let c of cuboids ) {
8
+ c . sort ( ( a , b ) => a - b )
9
+ }
10
+ const { max } = Math
11
+ cuboids . sort ( compare )
12
+ const f = Array ( n )
13
+ let ans = 0
14
+ for ( let i = 0 ; i < n ; i ++ ) {
15
+ f [ i ] = cuboids [ i ] [ 2 ]
16
+ for ( let j = 0 ; j < i ; j ++ ) {
17
+ if (
18
+ cuboids [ i ] [ 0 ] <= cuboids [ j ] [ 0 ] &&
19
+ cuboids [ i ] [ 1 ] <= cuboids [ j ] [ 1 ] &&
20
+ cuboids [ i ] [ 2 ] <= cuboids [ j ] [ 2 ]
21
+ )
22
+ f [ i ] = max ( f [ i ] , f [ j ] + cuboids [ i ] [ 2 ] )
23
+ }
24
+ ans = max ( ans , f [ i ] )
25
+ }
26
+ return ans
27
+ function compare ( a , b ) {
28
+ if ( a [ 0 ] != b [ 0 ] ) return b [ 0 ] - a [ 0 ]
29
+ if ( a [ 1 ] != b [ 1 ] ) return b [ 1 ] - a [ 1 ]
30
+ return b [ 2 ] - a [ 2 ]
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments