Skip to content

Commit 779d029

Browse files
committed
0200-number-of-islands.md Renamed and formatted.
1 parent 5da453f commit 779d029

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

problems/0200-number-of-islands-2.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ class Solution {
140140
if (grid[i][j] == '1') {
141141
islandCount++;
142142

143-
breadthFirstSearch(new int[]{i, j});
143+
depthFirstSearch(new int[]{i, j});
144144
}
145145
}
146146
}
147147

148148
return islandCount;
149149
}
150150

151-
void breadthFirstSearch(int[] point) {
151+
void depthFirstSearch(int[] point) {
152152
pointStack.push(point);
153153

154154
while (!pointStack.empty()) {
@@ -193,6 +193,7 @@ private:
193193
while (!point_stack.empty()) {
194194
point = point_stack.top();
195195
point_stack.pop();
196+
196197
int i = point[0];
197198
int j = point[1];
198199

@@ -253,15 +254,15 @@ var numIslands = function (grid_) {
253254
if (item === '1') {
254255
islandCount++
255256
256-
breadthFirstSearch([i, j])
257+
depthFirstSearch([i, j])
257258
}
258259
})
259260
})
260261
261262
return islandCount
262263
};
263264
264-
function breadthFirstSearch(point) {
265+
function depthFirstSearch(point) {
265266
pointStack.push(point)
266267
267268
while (pointStack.length > 0) {
@@ -308,15 +309,15 @@ public class Solution
308309
{
309310
islandCount++;
310311

311-
breadthFirstSearch([i, j]);
312+
depthFirstSearch([i, j]);
312313
}
313314
}
314315
}
315316

316317
return islandCount;
317318
}
318319

319-
void breadthFirstSearch(int[] point)
320+
void depthFirstSearch(int[] point)
320321
{
321322
pointStack.Push(point);
322323

problems/0200-number-of-islands.md

+26-32
Original file line numberDiff line numberDiff line change
@@ -230,45 +230,42 @@ public:
230230
let grid
231231
232232
var numIslands = function (grid_) {
233-
grid = grid_
234-
let islandCount = 0
233+
grid = grid_
234+
let islandCount = 0
235235
236-
grid.forEach((row, i) => {
237-
row.forEach((item, j) => {
238-
if (item === '1') {
239-
islandCount++
236+
grid.forEach((row, i) => {
237+
row.forEach((item, j) => {
238+
if (item === '1') {
239+
islandCount++
240240
241-
depthFirstSearch([i, j])
242-
}
243-
})
244-
})
241+
depthFirstSearch([i, j])
242+
}
243+
})
244+
})
245245
246-
return islandCount
246+
return islandCount
247247
};
248248
249249
function depthFirstSearch(point) {
250-
const [i, j] = point
250+
const [i, j] = point
251251
252-
if (i < 0 || i >= grid.length) {
253-
return
254-
}
252+
if (i < 0 || i >= grid.length) {
253+
return
254+
}
255255
256-
if (j < 0 || j >= grid[0].length) {
257-
return
258-
}
256+
if (j < 0 || j >= grid[0].length) {
257+
return
258+
}
259259
260-
if (grid[i][j] != '1') {
261-
return
262-
}
260+
if (grid[i][j] != '1') {
261+
return
262+
}
263263
264-
grid[i][j] = 'V';
264+
grid[i][j] = 'V';
265265
266-
[
267-
[i - 1, j],
268-
[i + 1, j],
269-
[i, j - 1],
270-
[i, j + 1]
271-
].forEach((adjacentPoint) => depthFirstSearch(adjacentPoint))
266+
[[i - 1, j], [i, j + 1], [i + 1, j], [i, j - 1]].forEach(
267+
(adjacentPoint) => depthFirstSearch(adjacentPoint)
268+
)
272269
}
273270
```
274271

@@ -315,10 +312,7 @@ public class Solution
315312

316313
grid[i][j] = 'V';
317314

318-
int[][] adjacentPoints = [
319-
[i - 1, j], [i, j + 1],
320-
[i + 1, j], [i, j - 1]
321-
];
315+
int[][] adjacentPoints = [[i - 1, j], [i, j + 1], [i + 1, j], [i, j - 1]];
322316

323317
foreach (var adjacentPoint in adjacentPoints) {
324318
depthFirstSearch(adjacentPoint);

0 commit comments

Comments
 (0)