import java.util.*;


public class Solution {
    /**
     * 判断岛屿数量
     * @param grid char字符型二维数组 
     * @return int整型
     */
    public int solve (char[][] grid) {
        // write code here
        int count=0;
        int m=grid.length;
        int n=grid[0].length;
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(grid[i][j]=='1'){
                    gg(grid,i,j);
                    count++;
                }
            }
        }
        return count;
    }
    public static void gg(char [][]grid,int i,int j){
        if(i<0||i>=grid.length||j<0||j>=grid[0].length ||grid[i][j]=='0'){
            return;
        }
        grid[i][j]='0';
        gg(grid,i+1,j);//向由找
        gg(grid,i,j+1);//向上找
        gg(grid,i,j-1);//向下找
        gg(grid,i-1,j);//向左找
    }
}