Skip to content

Commit e8ceebe

Browse files
committed
Added comment for 200-number-of-islands about marking visited.
1 parent 91ca6b1 commit e8ceebe

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

solutions/1-1000/200-number-of-islands-2.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Solution:
118118
if self.grid[i][j] != '1':
119119
continue
120120

121-
self.grid[i][j] = 'V'
121+
self.grid[i][j] = 'V' # For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
122122

123123
self.vertex_stack.append((i, j - 1))
124124
self.vertex_stack.append((i + 1, j))
@@ -169,7 +169,7 @@ class Solution {
169169
continue;
170170
}
171171

172-
grid[i][j] = 'V';
172+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
173173

174174
vertexStack.push(new int[]{i, j - 1});
175175
vertexStack.push(new int[]{i + 1, j});
@@ -209,7 +209,7 @@ private:
209209
continue;
210210
}
211211

212-
grid_[i][j] = 'V';
212+
grid_[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
213213

214214
vertex_stack.push({i, j - 1});
215215
vertex_stack.push({i + 1, j});
@@ -279,7 +279,7 @@ function depthFirstSearch(vertex) {
279279
continue
280280
}
281281

282-
grid[i][j] = 'V';
282+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
283283

284284
vertexStack.push([i, j - 1])
285285
vertexStack.push([i + 1, j])
@@ -340,7 +340,7 @@ public class Solution
340340
continue;
341341
}
342342

343-
grid[i][j] = 'V';
343+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
344344
345345
vertexStack.Push([i, j - 1]);
346346
vertexStack.Push([i + 1, j]);
@@ -395,7 +395,7 @@ func depthFirstSearch(vertex []int) {
395395
continue
396396
}
397397

398-
grid[i][j] = 'V'
398+
grid[i][j] = 'V' // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
399399

400400
vertexStack.Push([]int{i, j - 1})
401401
vertexStack.Push([]int{i + 1, j})
@@ -440,7 +440,7 @@ def depth_first_search(vertex)
440440

441441
next if @grid[i][j] != '1'
442442

443-
@grid[i][j] = 'V'
443+
@grid[i][j] = 'V' # For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as pushing `vertex_stack`. Because the adjacent veticies could be a lot, and it will cause performance issue.
444444

445445
@vertex_stack << [i, j - 1]
446446
@vertex_stack << [i + 1, j]

solutions/1-1000/200-number-of-islands-3.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Solution:
108108
if self.grid[i][j] != '1':
109109
continue
110110

111-
self.grid[i][j] = 'V'
111+
self.grid[i][j] = 'V' # For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
112112

113113
self.vertex_queue.append((i - 1, j))
114114
self.vertex_queue.append((i, j + 1))
@@ -159,7 +159,7 @@ class Solution {
159159
continue;
160160
}
161161

162-
grid[i][j] = 'V';
162+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
163163

164164
vertexQueue.add(new int[]{i - 1, j});
165165
vertexQueue.add(new int[]{i, j + 1});
@@ -199,7 +199,7 @@ private:
199199
continue;
200200
}
201201

202-
grid_[i][j] = 'V';
202+
grid_[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
203203

204204
vertex_queue.push({i - 1, j});
205205
vertex_queue.push({i, j + 1});
@@ -269,7 +269,7 @@ function breadthFirstSearch(vertex) {
269269
continue
270270
}
271271

272-
grid[i][j] = 'V';
272+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
273273

274274
vertexQueue.enqueue([i - 1, j])
275275
vertexQueue.enqueue([i, j + 1])
@@ -332,7 +332,7 @@ public class Solution
332332
continue;
333333
}
334334

335-
grid[i][j] = 'V';
335+
grid[i][j] = 'V'; // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
336336
337337
vertexQueue.Enqueue([i - 1, j]);
338338
vertexQueue.Enqueue([i, j + 1]);
@@ -387,7 +387,7 @@ func breadthFirstSearch(vertex []int) {
387387
continue
388388
}
389389

390-
grid[i][j] = 'V'
390+
grid[i][j] = 'V' // For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
391391

392392
vertexQueue.Enqueue([]int{i - 1, j})
393393
vertexQueue.Enqueue([]int{i, j + 1})
@@ -432,7 +432,7 @@ def breadth_first_search(vertex)
432432

433433
next if @grid[i][j] != '1'
434434

435-
@grid[i][j] = 'V'
435+
@grid[i][j] = 'V' # For island problems, its OK to mark visited at this place. For other graph problems, we need to use `visited_vertex_set` and mark visited as soon as enqueuing `vertex_queue`. Because the adjacent veticies could be a lot, and it will cause performance issue.
436436

437437
@vertex_queue << [i - 1, j]
438438
@vertex_queue << [i, j + 1]

0 commit comments

Comments
 (0)