Java Solution


  • 0
    Z

    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 oneCount4-repeatCount2;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.