Very easy solution


  • -1
    P
    int islandPerimeter(vector<vector<int>>& grid) {
            int res;
            for(int i=0; i <grid.size();i++){
                for(int j=0; j<grid[i].size(); j++){
                    if (grid[i][j] == 1)
                        ++res;
                }
            }
            return res * 2 + 2;
        }
    

Log in to reply
 

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