class Solution {
public:
    void dfs(vector<vector<char> >& grid, int i, int j, int row, int col)
    {
        if (i<0 || i>=row || j<0 || j>= col || grid[i][j]=='0') return ;
        grid[i][j] = '0';
        dfs(grid, i-1, j, row, col);
        dfs(grid, i+1, j, row, col);
        dfs(grid, i, j-1, row, col);
        dfs(grid, i, j+1, row, col);
        return;
    }
    /**
     * 判断岛屿数量
     * @param grid char字符型vector<vector<>> 
     * @return int整型
     */
    int solve(vector<vector<char> >& grid) {
        // write code here
        int n = grid.size(), m = grid[0].size();
        int result = 0;
        for (int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(grid[i][j]=='1')
                {
                    result += 1;
                    dfs(grid, i, j, n, m);
                }
            }
        }
        return result;
    }
};