We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e965a64 commit d5b03d3Copy full SHA for d5b03d3
463. Island Perimeter.java
@@ -0,0 +1,29 @@
1
+public class Solution {
2
+ public int islandPerimeter(int[][] grid) {
3
+ int perimeter = 0;
4
+
5
+ for (int row = 0; row < grid.length; row++) {
6
+ for (int col = 0; col < grid[row].length; col++) {
7
+ if (grid[row][col] == 1) {
8
+ int nAdj = 0;
9
10
+ if (row == 0 || grid[row-1][col] == 0)
11
+ nAdj++;
12
13
+ if (col == 0 || grid[row][col-1] == 0)
14
15
16
+ if (row == grid.length - 1 || grid[row+1][col] == 0)
17
18
19
+ if (col == grid[row].length - 1 || grid[row][col+1] == 0)
20
21
22
+ perimeter += nAdj;
23
+ }
24
25
26
27
+ return perimeter;
28
29
+}
0 commit comments