leetcode 695. Max Area of Island | 695. 岛屿的最大面积(DFS)
题目
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)相关推荐
- 695. Max Area of Island (Medium)——岛屿的最大面积
前言: 本题目为深度优先遍历(DFS) 算法的一道典型例题. 题目 : 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成 ...
- 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 ...
- [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 ...
- [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 ...
- 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) ...
- 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], ...
- LeetCode - 695. Max Area of Island (Java)
R.C记录矩阵行列 可以将邻接矩阵转为邻接表来做,即要将二维数组转换为一维数组: 将二维坐标转化为一维坐标: V = x * C + y 若将一维坐标转化为二维坐标: x = V / C y = V ...
- C#LeetCode刷题之#695-岛屿的最大面积( Max Area of Island)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3736 访问. 给定一个包含了一些 0 和 1的非空二维数组 gr ...
- Leetcode695.Max Area of Island岛屿的最大面积
给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合.你可以假设二维矩阵的四个边缘都被水包围着. 找到给定的二维数组中 ...
最新文章
- android switcher控件,Android ViewSwitcher 的功能与用法
- authc过滤器 shiro_Shiro的web下的使用
- 计算机启动程序bios_如何构建自己的计算机,第三部分:准备BIOS
- 算法设计与分析:(二)动态规划
- linux中 目标不是目录,Linux 中的 Install命令
- android 崩溃日志捕获,安卓Java崩溃的捕获和日志记录
- vs2010 打开 vs2012 的解决方案
- 2021回顾 | AI 领域十大研究趋势及必读论文
- 【微信小程序模板直接套用】微信小程序制作模板套用平台
- 15个常用excel函数公式_工作中常用的excel函数公式大全,拿来即用!
- yshon对讲机如何调频率_对讲机频率怎么调?四步教你给对讲机调频
- 如何根据商品条码查询商品名称和价格信息?
- 无GPU条件下安装caffe
- linux下tomcat的访问权限,关于Linux权限引起的Tomcat项目404问题
- 第14课:实战之用 Python 写一个简易爬虫
- EmguCV的配置和获取摄像头画面
- 机器学习电脑配置有什么要求?要什么显卡?
- 考研复试c语言面试题三峡,2017年三峡大学C语言程序设计(复试)考研真题硕士研究生入学考试试题...
- 大数据时代,AIoT在智慧社区的深度应用
- 全网最详细的Transformer的源码解读