public int numIslands(char[][] grid) {
        if (grid == null) return 0;

        int cnt = 0;
        for (int i = 0; i < grid.length; ++i) {
            for (int j = 0; j < grid[0].length; ++j) {
                if (grid[i][j] == '1') {
                    ++cnt;
                    destroy(grid, i, j);
                }
            }
        }
        return cnt;
    }