xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

LeetCode 海洋中岛屿数量问题算法题解 All In One

LeetCode 海洋中岛屿数量问题算法题解 All In One

二维矩阵
链表

200. 岛屿数量

  1. 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://neetcode.io/

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/

  1. 墙与门

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 发布文章使用:只允许注册用户才可以访问!


posted @   xgqfrms  阅读(539)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-08-21 js & touch event & swipe
2019-08-21 EventEmitter & custom events
2019-08-21 ES6 Class & super All In One
2019-08-21 Typescript All In One
2019-08-21 promise & async
2019-08-21 ios clipboard duplicate bug
2019-08-21 GitHub & two-factor authentication
点击右上角即可分享
微信分享提示