diff options
Diffstat (limited to 'furthest_building_reach.cpp')
-rw-r--r-- | furthest_building_reach.cpp | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/furthest_building_reach.cpp b/furthest_building_reach.cpp deleted file mode 100644 index 6baff33..0000000 --- a/furthest_building_reach.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "leetcode.h" - -class Solution { -public: - int furthestBuilding(vector<int> &heights, int bricks, int ladders) { - int n = heights.size() - 1; - priority_queue<int> pq; - for (int i = 0; i < n; i++) { - int diff = heights[i + 1] - heights[i]; - if (diff > 0) { - if (ladders) - pq.push(-diff), ladders--; - else if (!pq.empty() && diff > -pq.top()) { - pq.push(-diff); - bricks += pq.top(); - pq.pop(); - } else - bricks -= diff; - if (bricks < 0) - return i; - } - } - return n; - } -}; - -int main() { - Solution obj; - vector<int> heights = {4, 2, 7, 6, 9, 14, 12}; - int bricks = 5, ladders = 1; - cout << obj.furthestBuilding(heights, bricks, ladders); -} |