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.
[codes on Leetcode]https://leetcode.com/problems/furthest-building-you-can-reach/solutions/4739378/greedy-minheap-vs-multiset-43ms-beats100/
[Leetcode playList]https://www.youtube.com/watch?v=WjrWkPysfRM&list=PLYRlUBnWnd5IdDHk2BjqXwesydU17z_xk
[Dynamic Programming Playlist]https://www.youtube.com/watch?v=30yq3fmE6E8&list=PLYRlUBnWnd5K_XYUesV9oc6M9ONXII61T
沒有留言:
張貼留言