Furthest Building You Can Reach LeetCode solution in Python

1
class Solution:
2
def furthestBuilding(self, H: List[int], B: int, L: int) -> int:
3
heap = []
4
for i in range(len(H) - 1):
5
diff = H[i + 1] - H[i]
6
if diff > 0:
7
if L > 0:
8
heappush(heap, diff)
9
L -= 1
10
elif heap and diff > heap[0]:
11
heappush(heap, diff)
12
B -= heappop(heap)
13
else:
14
B -= diff
15
if B < 0:
16
return i
17
return len(H) - 1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0