深度优先dfs。遍历矩阵,从矩阵中的每个位置开始dfs周围是'1'的位置,dfs的同时修改'1'为'0'作为标记。思路在于每次走遍一块陆地,并将这一块陆地修改为海洋。 class Solution { public: /** * 判断岛屿数量 * @param grid char字符型vector<vector<>> * @return int整型 */ struct Pos{ int dx; int dy; }; vector<Pos> dir{{-1,0},{0,1},{1,0},{0,-1}}; void dfs(vector<vector<...