一、题目
二、代码
class Solution
{
public:
int islandPerimeter(vector<vector<int>>& grid)
{
int i,j;
int return_int=0;
for(i=0;i<grid.size();i++)
{
for(j=0;j<grid[i].size();j++)
{
if(grid[i][j]==1)
{
if(j==grid[i].size()-1||grid[i][j+1]!=1) return_int++;
if(j==0||grid[i][j-1]!=1) return_int++;
if(i==0||grid[i-1][j]!=1) return_int++;
if(i==grid.size()-1||grid[i+1][j]!=1) return_int++;
//std::cout<<" j "<<j<<" return_int "<<return_int<<std::endl;
}
}
// std::cout<<" ii "<<i<<" return_int "<<return_int<<std::endl;
}
return return_int;
}
};