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 ...
随机推荐
- Mysql 密码相关
MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格 一.密码复杂度 1.密码复杂度配置文件:/etc/my.cnf (CentOS 7下) ...
- CentOS ./configure && make && make install详解
码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install). 在Linux中利用源码包安装软件最重要的就是要仔细阅读安装包当中的README INST ...
- numpy的使用数组的创建2
随机创建了长度为十的数组 获得十以类的随机整数 快速获取数组2乘3维的数组 生成20个1到10之间的数组 通过reshape 将这些数变成二位数组 shape这个方法可以查看数组中的元素是几行几列的
- e-olymp Problem11 Big accuracy
传送门:点我 Big accuracy The rational fraction m/n is given. Write it in the decimal notation with k digi ...
- 2018年全国多校算法寒假训练营练习比赛(第四场)F:Call to your teacher
传送门:https://www.nowcoder.net/acm/contest/76/F 题目描述 从实验室出来后,你忽然发现你居然把自己的电脑落在了实验室里,但是实验室的老师已经把大门锁上了.更糟 ...
- sql case 与 sum
<select id="selectTotal" resultType="java.util.Map" parameterType="java. ...
- [LeetCode_96] Unique Binary Search Trees
题目链接 https://leetcode.com/problems/unique-binary-search-trees/ 题意 计算给定节点数的BST有多少种 思路 递归 相关知识 二叉搜索树(B ...
- iOS指令集
公司在进行项目重构时,其中一个地方的改动就是调整了iOS的指令集.更改指令集主要可以对手机应用的安装机型做出控制,同时在研发过程中也可以控制相关的模拟器和真机.它们原则上是向下兼容的,比如iphone ...
- c++笔试题贪吃蛇问题
贪吃蛇 现在有一个N*M(N,M=100)的方形矩形,在这个矩形的每一个方格上都放有一个随机值,一条可爱的小蛇从矩形的 左上角开始出发,每次移动都只能移动一格,向右或向下,而每到达一格贪吃的小蛇都会吧 ...
- 项目总结15:JavaScript模拟表单提交(实现window.location.href-POST提交数据效果)
JavaScript模拟表单提交(实现window.location.href-POST提交数据效果) 前沿 1-在具体项目开发中,用window.location.href方法下载文件,因windo ...