0ms |C++ Py3| BFS使用deque解Leetcode 3286 Find a Safe Walk Through a Grid
了解以下幾點有助於解決最短路徑問題:
所有權重相同時,只需使用基於佇列queue的廣度優先搜尋(BFS over queue)
權重有兩種非負值(如本題所示),使用基於雙端佇列(deque)的廣度優先搜尋(BFS over deque)
----
It's good to know: To solve the shortes path problem
all weights are same, just use BFS over queue
2 kinds of non-negative weights, like in this question, use BFS over deque
different positive weights, BFS over priority queue (Dijkstra-like)
沒有留言:
張貼留言
HTML 編輯器