題目
思路:
- 可以找到最小可重複動作嗎?
- 題目的 method 要傳入 first node, 回傳它的 clone
- 最小可重複動作可設定為:給定一個 node, 回傳 its clone
- DFS: 先寫 recursive case
- Base case: method 收到已 clone 過的 node
- Use a dict to record nodes been cloned.
- 須注意傳入 cloneGraph 的 node 有可能是 None
題目
思路:
題目
思路:
k 是 i 到 j 之間的任意點。比較 i -> j 經過所有 k 的距離,最小的即為 i -> j 的最短距離。i -> 2 -> 1 -> j and the iteration consider k == 1 first. But the dist[i][1] not yet populated and still have value of float('inf'). It will have the actual value until k == 2.
Update your browser to view this website correctly. Update my browser now