Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
Input:
11110
11010
11000
00000
Output: 1
Example 2:
Input:
11000
11000
00100
00011
Output: 3
思路:DFS代码更简单
1、每当访问到一个1、就dfs这个节点、将他四周合法的节点且也为1的节点全部赋值为0、并保持这样的dfs遍历每一个合法节点
2、这样子只要是连接在一起的就会全部被赋值为0、这样子就可以计算出有几个island