LeetCode 200. Number of Islands
LeetCode题解专栏:LeetCode题解
LeetCode 所有题目总结:LeetCode 所有题目总结
大部分题目C++,Python,Java的解法都有。
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
c++ dfs解法
class Solution {
public:
int numIslands(vector<vector<char>>& grid)
{
int nr = grid.size();
if(nr <= 0)
{
return 0;
}

这篇博客介绍了如何使用深度优先搜索(DFS)解决LeetCode上的200号问题——Number of Islands。博主提供了详细的解题思路,并给出了C++的实现方案。例子展示了不同情况下的岛屿计数,文章还提到了该问题的其他可能解法。
最低0.47元/天 解锁文章
393

被折叠的 条评论
为什么被折叠?



