#include <queue>
#include <vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 判断岛屿数量
* @param grid char字符型vector<vector<>>
* @return int整型
*/
vector<pair<int,int>> vis;
bool haveIn(pair<int,int> p){
for(int i=0;i<vis.size();i++){
if(vis[i].first==p.first&&vis[i].second==p.second){
return false;
}
}
return true;
}
int solve(vector<vector<char> >& grid) {
// write code here
int n=grid.size();//岛屿数量;
int m=grid[0].size();
int count=0;
if(n==0)
return 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(grid[i][j]=='1'){
count++;
queue<pair<int,int>> qu;
qu.push(pair<int,int>(i,j));
while(!qu.empty()){
vis.push_back(qu.front());
pair<int,int> temp=qu.front();
qu.pop();
int x=temp.first;int y=temp.second;
grid[x][y]=0;
if(x-1>=0&&
grid[x-1][y]=='1'){
qu.push(pair<int, int>(x-1,y));
}
if(x+1<n&&
grid[x+1][y]=='1'){
qu.push(pair<int, int>(x+1,y));
}
if(y-1>=0&&
grid[x][y-1]=='1'){
qu.push(pair<int, int>(x,y-1));
}
if(y+1<m&&
grid[x][y+1]=='1'){
qu.push(pair<int, int>(x,y+1));
}
}
}
}
}
return count;
}
};