class Solution {//V+E V public: bool canVisitAllRooms(vector<ve...
class Solution {//m*n public: vector<vector<int>> pacificAtlan...
continue 就是換下一個方向 — if not (0 <= nextRow < rows and 0 <= nextCol < c...
dir[4][2]; 4 個方向,每個方向需要 2 個數字:x 改多少、y 改多少。 visited[x][y] = 1; 1 = 走過;0 = 沒走過。 di...
1.void = 沒有回傳值。這個 dfs() 只是去修改 visited,不需要 return 一個數字或陣列,所以用 void。它有做事,但沒有回傳東西。...
visited[x][y] = true; 不是「先假裝走過」,而是:DFS 一進入 (x,y) 這格,就代表你現在已經走到這格了,所以立刻標記 true...
Ocean 四邊 題目已知這些格子直接碰到海,所以從這裡反向開始 visited=true 已經進到這格,立刻記錄避免繞回來inside一定先確認座標合法...
1.undirected graph(無向圖)分兩隊2.graph二維 每一個節點都可能連很多節點,所以每個節點需要一個 list。3.cur next4.二分...
example開始↓0 還沒分組↓0 = +1↓0 連到 1↓1 還沒分組↓1 = -1↓1 連到 2↓2 還沒分組↓2 = +1↓繼續 DFS 對應: 0...
1.流程 isBipartite()│├─ cur = 0│ ││ ├─ team[0] == 0│ ││ ├─ team[0] = +1...