Maximum Height by Stacking Cuboids LeetCode solution in Python

1
# Runtime: 199 ms (Top 36.11%) | Memory: 13.8 MB (Top 87.22%)
2

3

4
class Solution:
5
def maxHeight(self, cuboids: List[List[int]]) -> int:
6
dp = [0] * len(cuboids)
7
max_value = 0
8
for i in range(len(cuboids)):
9
cuboids[i].sort()
10
cuboids.sort()
11
for i in range(len(cuboids)):
12
dp[i] = cuboids[i][2]
13
for j in range(i):
14
if (
15
cuboids[i][0] >= cuboids[j][0]
16
and cuboids[i][1] >= cuboids[j][1]
17
and cuboids[i][2] >= cuboids[j][2]
18
):
19
dp[i] = max(dp[i], dp[j] + cuboids[i][2])
20
if dp[i] > max_value:
21
max_value = dp[i]
22
return max_value

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0