Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int:
- pq = []
- n = len(heights)
- remSum = 0
- ans = n-1
- for i in range(1, n):
- x = max(heights[i] - heights[i-1], 0)
- if x == 0:
- continue
- heappush(pq, x)
- if len(pq) > ladders:
- remSum += heappop(pq)
- if remSum > bricks:
- ans = i-1
- break
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement