695. Max Area of Island
static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int maxAreaOfIsland(vector<vector<int>>& grid)
{
int x=grid.size();
int y=grid[].size();
int res=;
for(int i=;i<x;i++)
{
for(int j=;j<y;j++)
{
res=max(res,countarea(grid,i,j));
}
}
return res;
} int countarea(vector<vector<int>> &grid,int i,int j)
{
int szx=grid.size();
int szy=grid[].size();
int count=;
if(grid[i][j]==)
{
count++;
grid[i][j]=;
if(valid(i-,j,szx,szy)) count+=countarea(grid,i-,j);
if(valid(i,j-,szx,szy)) count+=countarea(grid,i,j-);
if(valid(i+,j,szx,szy)) count+=countarea(grid,i+,j);
if(valid(i,j+,szx,szy)) count+=countarea(grid,i,j+);
return count;
}
return ;
} bool valid(int i,int j,int szx,int szy)
{
return i>=&&i<szx&&j>=&&j<=szy;
} };
递归,问题不大
695. Max Area of Island的更多相关文章
- leetcode 200. Number of Islands 、694 Number of Distinct Islands 、695. Max Area of Island 、130. Surrounded Regions
两种方式处理已经访问过的节点:一种是用visited存储已经访问过的1:另一种是通过改变原始数值的值,比如将1改成-1,这样小于等于0的都会停止. Number of Islands 用了第一种方式, ...
- [leetcode]python 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 ...
- 200. Number of Islands + 695. Max Area of Island
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- 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 ...
- 【easy】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) ...
- 695. Max Area of Island最大岛屿面积
[抄题]: 求最多的联通的1的数量 Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (repre ...
- 695. Max Area of Island@python
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 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:BFS 日期 题目地址:ht ...
- [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 ...
随机推荐
- 两条线段求交点+叉积求面积 poj 1408
题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...
- Linux下安装和使用nginx
浏览器和服务器的关系 NGINX nginx是什么 nginx是一个开源的,支持高性能,高并发的www服务和代理服务软件. nginx不但是一个优秀的web服务软件,还可以作为反向代理,负载均衡,以及 ...
- 189. Rotate Array(Array)
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- C# 关于委托
例如: public class test:Form { //定义委托 public delegate void GetSql(string sql); //定义装载委托的属性 public GetS ...
- nodemcu生成LUA版本固件
构建自己的固件地址 https://nodemcu-build.com/
- C++ 中的RTTI机制详解
前言 RTTI是”Runtime Type Information”的缩写,意思是运行时类型信息,它提供了运行时确定对象类型的方法.RTTI并不是什么新的东西,很早就有了这个技术,但是,在实际应用中使 ...
- Python数据分析--Pandas知识点(二)
本文主要是总结学习pandas过程中用到的函数和方法, 在此记录, 防止遗忘. Python数据分析--Pandas知识点(一) 下面将是在知识点一的基础上继续总结. 13. 简单计算 新建一个数据表 ...
- mysql 安装后出现 10061错误
#服务器端 提示 The vervice already exists! The current server installed #mysqld 服务没有启动 解决办法 移除原来的mysql服务 ...
- 10.16JS日记
1.parseint() 2.parsefloat() 这两个单词运行的时候遇到第一个非数字就结束了 3.var a="hello word" a这个变量为字符串,每一个字母为字 ...
- Redis进阶实践之二十 Redis的配置文件使用详解
一.引言 写完上一篇有关redis使用lua脚本的文章,就有意结束Redis这个系列的文章了,当然了,这里的结束只是我这个系列的结束,但是要学的东西还有很多.但是,好多天过去了,总是感觉好像还缺点什么 ...