Advertisement
smj007

Buildings with an Ocean View

Aug 15th, 2024
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. class Solution:
  2.     def findBuildings(self, heights: List[int]) -> List[int]:
  3.  
  4.         last = len(heights) - 1
  5.         heights.append(-1)
  6.         result = [-1]
  7.  
  8.         while last >= 0:
  9.             if heights[last] > heights[result[-1]]:
  10.                 result.append(last)
  11.             last -= 1
  12.  
  13.         return result[::-1][:-1]
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement