C++ python貪婪排序2 pointer解Leetcode 881 Boats to Save People
Greedy是這類問題的關鍵,片中先用sort, counting sort來排序,左有兩游標大小一對看能不能一次載兩人,逐次移動游標
Greedy is the key to this kind of problem. In the film, sort and counting sort are first used to sort. There are two pointers left & right, take one big and one small. See if you can take 2 people in a boat or not, move the pointers
[codes on Leetcode]https://leetcode.com/problems/boats-to-save-people/solutions/5108612/greedy-sort-counting-sort-then-2-pointer-7ms-beats-100/
[sliding window/2 pointer play list]https://www.youtube.com/watch?v=pi1XpQU_Yxo&list=PLYRlUBnWnd5KrCfs7qCFb-Bvn7dvnakFy
沒有留言:
張貼留言