herrDeng網內搜尋

自訂搜尋

Ads

2024年2月17日 星期六

C++貪婪演算與Min Heap解Leetcode 1642 Furthest Building You Can Reach

Leetcode問題1642. Furthest Building You Can Reach也是用Greedy演算,有梯子、有磚塊,要訣就是高度差大的用梯子,高度差小的用磚塊,至於容器,C++可用priority_queue或用make_heap,當然也可用multiset,用heap的解答當然很快速,千萬不要誤入歧途採用DP動態規劃,先看constraints就知。
---
The largest `ladders` jumps use ladders, the others use bricks. also uses Greedy algorithm. There are ladders and bricks. The key is to use ladders for large height differences and bricks for small height differences. As for containers, C++ can use priority_queue or make_heap, of course. Multiset can be used, and the solution using heap is of course very fast. Don't go astray and use  dynamic programming. Just look at constraints first.

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章