LeetCode 海洋中岛屿数量问题算法题解 All In One
LeetCode 海洋中岛屿数量问题算法题解 All In One
二维矩阵
链表
图
200. 岛屿数量
- Number of Islands
给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。
岛屿
总是被水包围
,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。
此外,你可以假设该网格的四条边均被水包围。
const getIslands = (arr = []) => {
const len = arr.length;
const counter = 0;
while(len) {
let row = arr[arr.length - len];
// let item;
let num = 0;
let cur = 0;
for (let i = 0; i < row.length; i++) {
let item = row[i];
if(item === `+`) {
num +=1;
let netxItem = row[i + 1];
// const nextRow = arr[arr.length - len + 1];
// let nextRowitem = nextRow[i];
if(item === netxItem) {
break;
}
}
}
}
}
https://leetcode.com/problems/number-of-islands
https://leetcode-cn.com/problems/number-of-islands/
LeetCode 题解 / LeetCode Solutions
YouTube & LeetCode 力扣官方算法题解视频列表
https://www.youtube.com/playlist?list=PLamwFu9yMruCBtS2tHUD77oI_Wsce-syE
https://www.youtube.com/channel/UCftIXZeipv4MTVwmfFphtYw/videos
https://github.com/xgqfrms/leetcode/issues/14
https://www.youtube.com/results?search_query=+Leetcode+200
https://github.com/neetcode-gh/leetcode/blob/main/javascript/200-Number-of-Islands.js
https://github.com/neetcode-gh/leetcode/blob/main/typescript/200-Number-of-Islands.ts
类似问题
https://leetcode.com/problems/surrounded-regions/
https://leetcode.com/problems/max-area-of-island/
https://leetcode.com/problems/count-sub-islands/
https://leetcode.com/problems/find-all-groups-of-farmland/
https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph/
- 墙与门
https://leetcode.com/problems/walls-and-gates/
https://leetcode.cn/problems/walls-and-gates/
https://leetcode.com/problems/number-of-islands-ii/
https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/
https://leetcode.com/problems/number-of-distinct-islands/
refs
DFS
https://zhuanlan.zhihu.com/p/133390668
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13538922.html
未经授权禁止转载,违者必究!