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的更多相关文章

  1. 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 用了第一种方式, ...

  2. [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 ...

  3. 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 ...

  4. 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. 【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) ...

  6. 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 ...

  7. 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 ...

  8. 【LeetCode】695. Max Area of Island 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:BFS 日期 题目地址:ht ...

  9. [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 ...

随机推荐

  1. ansible1

    前期工作: 第一步:下载epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 第二步: ...

  2. 【转】关于easyui的窗口和tab页面不执行js说明

    原地址:http://www.jeasyuicn.com/post-49.html 一直以来群里里面很多人反应,在用tab加载界面的时候,界面里面的js不会执行.今天GodSon在此说明一下原因. 不 ...

  3. js数组排序实用方法集锦

    前言: 据说程序员三个月就能忘记自己写的代码,所以最好是在有空的时候及时做些总结,记录下来,这样后边遇到类似问题的话,就可以直接先查看自己的博客了.写技术博客,对自己是一种总结,对别人,是一种参考. ...

  4. aruba 802.11ac协议

    上述功能为802.11ac协议,高密环境下建议不勾选. 附百度百科:虽然802.11ac标准草案提高了传输速度并增加了带宽,可以支持企业网络中数量越来越庞大的设备,但是企业开始发现,这个标准需要依赖于 ...

  5. 处理后台向前台传递的json数据

    在pom文件中添加下面三种依赖jar包 <dependency> <groupId>com.fasterxml.jackson.core</groupId> < ...

  6. tomcat实现多端口、多域名访问(只针对一个tomcat)

    说明:这个部分介绍如何在tomcat中进行配置,使同一个应用可以通过不同的端口号进行访问. 在某些需要进行安全控制的场景中会应用到.例如:不同地址段只能通过某个端口访问. 2 找到tomcat的主目录 ...

  7. 微信小程序 wxml中的属性记录

    1. view 标签中的属性 style 中的参数 margin-top:10px;  (向上距离) display : flex;  (display : flex 容器声明) flex-direc ...

  8. css背景图充满屏幕

    代码: body { /* 加载背景图 */ background: url(resource/inv_bg.png); /* 背景图不平铺 */background-repeat: no-repea ...

  9. 如何提高php应用的性能?

    1. 如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍.2.$row[’id’] 的速度是$row[id]的7倍.3.echo 比 print快,并且使用echo的 ...

  10. c# mac地址 和http://xx.xx.xx/ 正则表达式匹配

    Mac  :^([0-9a-fA-F]{2})(([/\s:][0-9a-fA-F]{2}){5})$ C# 书写方式 一下是允许mac中间间隔符是“:”或者“-”两种输入方式 并且我把上边的正则表达 ...