(matrix)
| 46 | // O(wh) time | O(wh) space |
| 47 | |
| 48 | function riverSizes(matrix) { |
| 49 | const sizes = []; |
| 50 | const visited = matrix.map((row) => row.map((value) => false)); |
| 51 | |
| 52 | for (let row = 0; row < matrix.length; row++) { |
| 53 | for (let col = 0; col < matrix[row].length; col++) { |
| 54 | if (visited[row][col]) continue; |
| 55 | traverseNode(row, col, matrix, visited, sizes); |
| 56 | } |
| 57 | } |
| 58 | return sizes; |
| 59 | } |
| 60 | |
| 61 | function traverseNode(row, col, matrix, visited, sizes) { |
| 62 | let currentRiverSize = 0; |
nothing calls this directly
no test coverage detected