1. static int wing=[]()
  2. {
  3. std::ios::sync_with_stdio(false);
  4. cin.tie(NULL);
  5. return ;
  6. }();
  7.  
  8. class Solution
  9. {
  10. public:
  11. int maxAreaOfIsland(vector<vector<int>>& grid)
  12. {
  13. int x=grid.size();
  14. int y=grid[].size();
  15. int res=;
  16. for(int i=;i<x;i++)
  17. {
  18. for(int j=;j<y;j++)
  19. {
  20. res=max(res,countarea(grid,i,j));
  21. }
  22. }
  23. return res;
  24. }
  25.  
  26. int countarea(vector<vector<int>> &grid,int i,int j)
  27. {
  28. int szx=grid.size();
  29. int szy=grid[].size();
  30. int count=;
  31. if(grid[i][j]==)
  32. {
  33. count++;
  34. grid[i][j]=;
  35. if(valid(i-,j,szx,szy)) count+=countarea(grid,i-,j);
  36. if(valid(i,j-,szx,szy)) count+=countarea(grid,i,j-);
  37. if(valid(i+,j,szx,szy)) count+=countarea(grid,i+,j);
  38. if(valid(i,j+,szx,szy)) count+=countarea(grid,i,j+);
  39. return count;
  40. }
  41. return ;
  42. }
  43.  
  44. bool valid(int i,int j,int szx,int szy)
  45. {
  46. return i>=&&i<szx&&j>=&&j<=szy;
  47. }
  48.  
  49. };

递归,问题不大

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. 枚举+最短路 poj1062

    这里有个非常坑的地方,还有比酋长地位还更高的人,我也是看了论坛才知道... 在这里我把编号1看成终点,优惠价格看成相应的替代品编号到可替代品编号的权值,比如说有了2再加8000就到了1,那么2到1的弧 ...

  2. Android 基础 (四大组件,五大存储,六大布局)

    Android四大组件: 参考:https://blog.csdn.net/shenggaofei/article/details/52450668 Android四大组件分别为activity.se ...

  3. Unity之MVC 模式

    MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发. Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO.它 ...

  4. 微信小程序接入百度统计

    一. 百度统计添加应用,获取appkey和微信小程序统计sdk: 1. 百度统计首页,点击“我的全部应用”右侧的添加按钮: 2. “应用类型”选择小程序统计,选择微信小程序,填写应用名称信息,选择内容 ...

  5. [剑指Offer]22-链表中倒数第k个结点

    题目链接 https://www.nowcoder.com/practice/529d3ae5a407492994ad2a246518148a?tpId=13&tqId=11167&t ...

  6. Java使用点滴

    1.查找某个字符在字符串中第几次出现的位置 /** * 查找某个字符在字符串中第几次出现的位置 * @param string 要匹配的字符串 * @param i 第几次出现 * @param ch ...

  7. elasticsearch命令

    如果安装了x-pack插件,需要验证 curl -u username:passwd 1.查看所有index curl -XGET localhost:/_cat/indices?v 2.清理所有in ...

  8. mysql decimal(10,2)对应java类型

    下面我给出MYSQL类型与JAVA类型对应表,希望能够帮到您: 类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) VARCHAR L+N VARCHAR java.lang.S ...

  9. Linux下Python2升级Python3

    Linux下Python2的升级方法: 一.下载Python3安装包: 1.在线下载 wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2 ...

  10. excel数据复制到html表格<textarea>中

    方案一 多行文本框接收到复制的excel值后,在文本框的chage事件中,将excel内容分割到二维数组中,然后填充到html的表格的input或textarea中. 数据格式: 单元格复制后的数据格 ...