摘要: dfs 遍历二维网格,如果网格值为“1”则以该网格为起点进行深度优先遍历,在搜索过程中值为1的网格都置为“0”。这样深度优先搜索的次数就是岛屿的数量。 class Solution { public int numIslands(char[][] grid) { int num = 0; int r 阅读全文
posted @ 2020-10-19 18:08 消灭猕猴桃 阅读(114) 评论(0) 推荐(0) 编辑