Graph
LeetCode 1306: Jump Game III
·1 分鐘
LeetCode
Medium
Bfs
Dfs
Graph
Array
LeetCode 1306 解題筆記:每個 index 是節點、往左右跳是邊,BFS 或 DFS 看能不能走到值為 0 的位置
LeetCode 3619: Count Islands With Total Value Divisible by K
·2 分鐘
LeetCode
Medium
Dfs
Bfs
Matrix
Graph
LeetCode 3619 解題筆記:網格 flood fill 加總每座島的值;格子到 10^5,用迭代避免遞迴太深
LeetCode 3613: Minimize Maximum Component Cost
·1 分鐘
LeetCode
Medium
Union-Find
Graph
Sorting
Binary-Search
LeetCode 3613 解題筆記:邊由小到大加進 Union-Find,剛好剩 k 塊時那條邊的權重就是答案;n <= k 時回傳 0
LeetCode 3608: Minimum Time for K Connected Components
·1 分鐘
LeetCode
Medium
Union-Find
Graph
Sorting
Binary-Search
LeetCode 3608 解題筆記:倒過來從時間大的邊開始加回去,第一次讓連通塊數少於 k 的那條邊的時間就是答案
LeetCode 3607: Power Grid Maintenance
·2 分鐘
LeetCode
Medium
Heap
Union-Find
Graph
Lazy-Deletion
LeetCode 3607 解題筆記:Union-Find 分群,每群一個 min-heap,離線的站用 lazy deletion
LeetCode 3493: Properties Graph
·1 分鐘
LeetCode
Medium
Graph
Dfs
Union-Find
Hash-Map
LeetCode 3493 解題筆記:先把每列轉成 set,兩兩比較交集大小建邊,再數連通塊
LeetCode 1791: Find Center of Star Graph
·1 分鐘
LeetCode
Easy
Graph
LeetCode 1791 解題筆記:中心點出現在每一條邊上,所以只要看前兩條邊的共同點
LeetCode 133: Clone Graph
·1 分鐘
LeetCode
Medium
Hash-Table
Depth-First-Search
Breadth-First-Search
Graph
LeetCode 133 解題筆記:DFS 時用雜湊表記住舊節點對應的新節點,遇到已經複製過的就直接回傳,避免無限遞迴;空圖回傳 None
LeetCode 997: Find the Town Judge
·1 分鐘
LeetCode
Easy
Array
Hash-Table
Graph
LeetCode 997 解題筆記:法官被其他 n - 1 個人信任而且不信任任何人,所以 in-degree - out-degree == n - 1