(row, col)
| 12 | let queue = []; |
| 13 | |
| 14 | const exploreIslandDFS = (row, col) => { |
| 15 | if ( |
| 16 | row < 0 || |
| 17 | row >= rows || |
| 18 | col < 0 || |
| 19 | col >= cols || |
| 20 | grid[row][col] !== 1 |
| 21 | ) { |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | queue.push([row, col]); |
| 26 | grid[row][col] = 2; |
| 27 | |
| 28 | exploreIslandDFS(row - 1, col); |
| 29 | exploreIslandDFS(row + 1, col); |
| 30 | exploreIslandDFS(row, col - 1); |
| 31 | exploreIslandDFS(row, col + 1); |
| 32 | |
| 33 | return true; |
| 34 | }; |
| 35 | |
| 36 | const buildBridgeBFS = () => { |
| 37 | let distance = -1; |