C Solution (runtime beats 97.52% of c submissions)


  • 0
    U

    int islandPerimeter(int** grid, int gridRowSize, int gridColSize) {
    int count = 0;
    for(int i = 0; i < gridRowSize; i++){
    for(int j = 0; j < gridColSize; j++){
    if(grid[i][j] == 1){
    if(i==0 || grid[i-1][j] == 0) count++;
    if(i==gridRowSize-1 || grid[i+1][j] == 0) count++;
    if(j==0 || grid[i][j-1] == 0) count++;
    if(j==gridColSize-1 || grid[i][j+1] == 0) count++;
    }
    }
    }
    return count;
    }


Log in to reply
 

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