public class Solution {

public int islandPerimeter(int[][] grid) {

int row=grid.length;

int oneCount=0;

int repeatCount=0;

for(int i=0;i<row;i++){

for(int j=0;j<grid[i].length;j++){

if(grid[i][j]==1){

oneCount++;

if(i<row-1&&grid[i+1][j]==1){

repeatCount++;

}

if(j<grid[i].length-1&&grid[i][j+1]==1){

repeatCount++;

}

}else{

continue;

}

}

}

return oneCount*4-repeatCount*2;

}

}