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 ...
随机推荐
- 《学习OpenCV(中文版)》
<模式识别中文版(希)西奥多里蒂斯> <学习OpenCV(中文版)> 矩阵计算 英文版 第四版 Matrix Computations OpenCV 3.x with Pyth ...
- Codeforces Beta Round #32 (Div. 2, Codeforces format)
Codeforces Beta Round #32 (Div. 2, Codeforces format) http://codeforces.com/contest/32 A #include< ...
- TZOJ 3315 买火车票(线段树区间最小值)
描述 Byteotian州铁道部决定赶上时代,为此他们引进了城市联网.假设城市联网顺次连接着n 个市从1 到n 编号(起始城市编号为1,终止城市编号为n).每辆火车有m个座位且在任何两个运送更多的乘客 ...
- PTA 7-8 哈利·波特的考试(floyd)
哈利·波特要考试了,他需要你的帮助.这门课学的是用魔咒将一种动物变成另一种动物的本事.例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等.反方向变化的魔咒就是简单地将原来的魔咒倒过来念 ...
- [LeetCode_94] Binary Tree Inorder Traversal
题目链接 https://leetcode.com/problems/binary-tree-inorder-traversal/ 题意 二叉树的中序遍历 思路 中序遍历:即"左中右&quo ...
- os & sys
os os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当于shell下cd os.c ...
- git add 文件夹
1. 本地新建好文件夹,在文件夹里新建*.md 2. 切换到文件夹父目录 3. git add 文件夹名 4. git commit 5. git push
- C#按制定的环境编译替换不出对应的配置项的解决措施。
1. 比如选择的 编译或者发布 环境是 QA ,但是QA里面配置的 替换节点 实际并没有被替换 解决方案: 在项目文件.csproj中最底部加入一下代码,应该成功.成功将QA的配置节点 替换掉默认的 ...
- Java泛型:List<?>与List的区别
为什么说List<?>是type-safe而List不是type-safe的? 1.List<?> compiler看到了你使用了wildcard ?,那么相当于你对compi ...
- iOS.CocoaPods.0
1. CocoaPods CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器. A CocoaPod (singular) is a speci ...