class Solution {
public:
vector<vector<int>> move = {{0,1}, {1,0}, {0,-1}, {-1,0}}; //y,x右下左上
void markIslands(vector<vector<char>>& grid, int y, int x){
for (int i=0; i<4; i++){
int newy = y + move[i][0];
int newx = x + move[i][1];
if (newy<0 || newx<0 || newy >= grid.size() || newx>= grid[0].size()) continue;
if (grid[newy][newx] == '1'){
grid[newy][newx] = 'a';
markIslands(grid, newy, newx);
}
}
return;
}
int numIslands(vector<vector<char>>& grid) {
int cnt = 0;
for (int i=0; i<grid.size(); i++){
for (int j = 0; j<grid[i].size(); j++){
if (grid[i][j] == '1'){
cnt++;
grid[i][j] = 'a';
markIslands(grid, i, j);
}
}
}
return cnt;
}
};