【leetcode】200. 岛屿数量
void dfs(char** grid, int gridSize, int* gridColSize, int r, int c){ if (r < 0 || r >= gridSize || c < 0 || c >= *gridColSize || grid[r][c] != '1') return; grid[r][c] = 'A'; dfs(grid, gridSize, gridColSize, r + 1, c); dfs(grid, gridSize, gridColSize, r - 1, c); dfs(grid, gridSize, gridColSize, r, c+1); dfs(grid, gridSize, gridColSize, r, c-1); } int numIslands(char** grid, int gridSize, int* gridColSize){ int i, j, cnt=0; for (i = 0; i < gridSize; i++){ for (j = 0; j < *gridColSize; j++){ if (grid[i][j] == '1'){ cnt++; dfs(grid, gridSize, gridColSize, i, j); } } } return cnt; }