(int[][] grid)
| 1 | // Time: 78 ms (85.12%) | Memory: 96.5 MB (51.90%) - LeetSync |
| 2 | class Solution { |
| 3 | public int islandPerimeter(int[][] grid) { |
| 4 | int rows = grid.length; |
| 5 | int cols = grid[0].length; |
| 6 | int perimeter = 0; |
| 7 | |
| 8 | for (int i = 0; i < rows; i++) { |
| 9 | for (int j = 0; j < cols; j++) { |
| 10 | if (grid[i][j] == 1) { |
| 11 | perimeter += 4; |
| 12 | if (i > 0 && grid[i - 1][j] == 1) perimeter -= 2; |
| 13 | if (j > 0 && grid[i][j - 1] == 1) perimeter -= 2; |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | return perimeter; |
| 18 | } |
| 19 | } |
nothing calls this directly
no outgoing calls
no test coverage detected