XOR


  • 0
    J

    int islandPerimeter(int** grid, int gridRowSize, int gridColSize) {
    int res = 0;

    for(int i=0;i<gridRowSize;i++)
    for(int j=0;j<gridColSize;j++)
    if(grid[i][j]){
        if(i==0)res+=1;else res+=(1^grid[i-1][j]);
        if(j==0)res+=1;else res+=(1^grid[i][j-1]);
        if(j==gridColSize-1)res+=1;else res+=(1^grid[i][j+1]);
        if(i==gridRowSize-1)res+=1;else res+=(1^grid[i+1][j]);
    }
    return res;
    

    }


Log in to reply
 

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