博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - 463. Island Perimeter
阅读量:7050 次
发布时间:2019-06-28

本文共 1313 字,大约阅读时间需要 4 分钟。

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn't have "lakes" (water inside that isn't connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.

 

[[0,1,0,0], [1,1,1,0], [0,1,0,0], [1,1,0,0]]Answer: 16Explanation: The perimeter is the 16 yellow stripes in the image below:

public class Solution {    public int islandPerimeter(int[][] grid) {        if (grid == null || grid.length <= 0 || grid[0] == null || grid[0].length <= 0)            return 0;                int high = grid.length, width = grid[0].length;        int p = 0;        for (int i=0; i
= high-1) p++; if (i
0 && grid[i-1][j] == 0) p++; if (j <= 0) p++; if (j >= width-1) p++; if (j>0 && grid[i][j-1] == 0) p++; if (j

 

转载于:https://www.cnblogs.com/wxisme/p/7306834.html

你可能感兴趣的文章
【PDF】Java操作PDF之iText超入门
查看>>
PHP:第五章——字符串过滤函数
查看>>
Spring中ApplicationContextAware的用法
查看>>
flask的session解读及flask_login登录过程研究
查看>>
ElasticSearch单机多实例环境部署
查看>>
python 练习
查看>>
Centos 安装 nload
查看>>
python3简单使用requests
查看>>
由一次java作业 引起的思考
查看>>
HDU 3389 Game(博弈)
查看>>
仅IE支持clearAttributes/mergeAttributes方法
查看>>
Linux中U盘和SD卡加载卸载命令
查看>>
github push403错误的处理
查看>>
Hibernate与 MyBatis的比较
查看>>
关于百度地图API的地图坐标转换问题
查看>>
【操作系统】设备管理(五)
查看>>
ArcObject开发时,axtoolbarcontrol中一些添加的按钮是灰色的问题
查看>>
[LeetCode] Guess Number Higher or Lower 猜数字大小
查看>>
netbeans 快捷键
查看>>
C#实现GDI+基本图的缩放、拖拽、移动
查看>>