题目

https://leetcode.com/problems/max-area-of-island/

题解

class Solution {int M, N;public int maxAreaOfIsland(int[][] grid) {M = grid.length;N = grid[0].length;boolean[][] visited = new boolean[M][N];int result = 0;for (int i = 0; i < M; i++) {for (int j = 0; j < N; j++) {if (!visited[i][j]) {result = Math.max(result, dfs(grid, i, j, visited));}}}return result;}public int dfs(int[][] board, int i, int j, boolean[][] visited) {if (i < 0 || i == M || j < 0 || j == N || visited[i][j]) return 0;visited[i][j] = true;int result = 0;if (board[i][j] == 1) {result += 1;result += dfs(board, i - 1, j, visited);result += dfs(board, i + 1, j, visited);result += dfs(board, i, j - 1, visited);result += dfs(board, i, j + 1, visited);}return result;}
}

leetcode 695. Max Area of Island | 695. 岛屿的最大面积(DFS)相关推荐

  1. 695. Max Area of Island (Medium)——岛屿的最大面积

    前言: 本题目为深度优先遍历(DFS) 算法的一道典型例题. 题目 : 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成 ...

  2. LeetCode 695. Max Area of Island

    LeetCode 695. Max Area of Island Given a non-empty 2D array grid of 0's and 1's, an island is a grou ...

  3. [Leetcode] Max Area of Island 最大岛屿面积

    Max Area of Island 最新更新请见:https://yanjia.me/zh/2019/02/... Given a non-empty 2D array grid of 0's an ...

  4. [swift] LeetCode 695. Max Area of Island

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  5. LeetCode 695 Max Area of Island

    题目: Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) ...

  6. LeetCode 695. Max Area of Island javascript解决方案

    题意: 寻找最大岛. leetcode.com/problems/ma- 传入: [[0,0,1,0,0,0,0,1,0,0,0,0,0],  [0,0,0,0,0,0,0,1,1,1,0,0,0], ...

  7. LeetCode - 695. Max Area of Island (Java)

    R.C记录矩阵行列 可以将邻接矩阵转为邻接表来做,即要将二维数组转换为一维数组: 将二维坐标转化为一维坐标: V = x * C + y 若将一维坐标转化为二维坐标: x = V / C y = V ...

  8. C#LeetCode刷题之#695-岛屿的最大面积( Max Area of Island)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3736 访问. 给定一个包含了一些 0 和 1的非空二维数组 gr ...

  9. Leetcode695.Max Area of Island岛屿的最大面积

    给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合.你可以假设二维矩阵的四个边缘都被水包围着. 找到给定的二维数组中 ...

最新文章

  1. android switcher控件,Android ViewSwitcher 的功能与用法
  2. authc过滤器 shiro_Shiro的web下的使用
  3. 计算机启动程序bios_如何构建自己的计算机,第三部分:准备BIOS
  4. 算法设计与分析:(二)动态规划
  5. linux中 目标不是目录,Linux 中的 Install命令
  6. android 崩溃日志捕获,安卓Java崩溃的捕获和日志记录
  7. vs2010 打开 vs2012 的解决方案
  8. 2021回顾 | AI 领域十大研究趋势及必读论文
  9. 【微信小程序模板直接套用】微信小程序制作模板套用平台
  10. 15个常用excel函数公式_工作中常用的excel函数公式大全,拿来即用!
  11. yshon对讲机如何调频率_对讲机频率怎么调?四步教你给对讲机调频
  12. 如何根据商品条码查询商品名称和价格信息?
  13. 无GPU条件下安装caffe
  14. linux下tomcat的访问权限,关于Linux权限引起的Tomcat项目404问题
  15. 第14课:实战之用 Python 写一个简易爬虫
  16. EmguCV的配置和获取摄像头画面
  17. 机器学习电脑配置有什么要求?要什么显卡?
  18. 考研复试c语言面试题三峡,2017年三峡大学C语言程序设计(复试)考研真题硕士研究生入学考试试题...
  19. 大数据时代,AIoT在智慧社区的深度应用
  20. 全网最详细的Transformer的源码解读

热门文章

  1. 牛客 - 配对(贪心+数学)
  2. HDU - 3338 Kakuro Extension(最大流+思维建边)
  3. 使用二维码识别技术的好处_人脸识别技术什么场景都能使用吗?
  4. UVA 725 Division(除法)
  5. TrackFormer解读
  6. Burpsuite中protobuf数据流的解析 - Vincent
  7. 在 Mac 上为 Android 编译 WebRTC
  8. Docker常用操作命令(一)
  9. idea下git log乱码问题
  10. Java多线程知识小抄集(四)——完结