GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/463_Island_Perimeter.java at master · mridullpandey/leetcode Expand file tree/ Copy path463_Island_Perimeter.javaMore file actions 16 lines (16 loc) · 709 Bytes / Copy path463_Island_Perimeter.javaFile metadata and controls16 lines (16 loc) · 709 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution { public int islandPerimeter(int[][] grid) { // https://leetcode.com/problems/island-perimeter/discuss/95001/clear-and-easy-java-solution int islands = 0, neighbours = 0; for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[i].length; j++) { if (grid[i][j] == 1) { islands++; // count islands if (i < grid.length - 1 && grid[i + 1][j] == 1) neighbours++; // count down neighbours if (j < grid[i].length - 1 && grid[i][j + 1] == 1) neighbours++; // count right neighbours } } } return islands * 4 - neighbours * 2; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |