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

本文共 1252 字,大约阅读时间需要 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

 

转载地址:http://mlukm.baihongyu.com/

你可能感兴趣的文章
Python知识点总结篇(五)
查看>>
一致性算法探寻(扩展版)1
查看>>
这几个 Chrome 的 Tab 增强插件你都用上了吗?
查看>>
Java中的浅拷贝与深拷贝
查看>>
微信小程序联盟:官方文档+精品教程+demo集合(6月9日更新,持续更新中……)...
查看>>
spring 事务的传播特性
查看>>
react学习(1)-Why React?
查看>>
RESTful风格的API接口开发教程
查看>>
用 Lua 实现一个微型虚拟机-基本篇
查看>>
php 安装 memcached 扩展出现 zlib 错误
查看>>
CentOS中服务程序随系统启动
查看>>
我的友情链接
查看>>
永久关闭selinux
查看>>
zTree 树使用$('#test').load("url"),后树不能使用
查看>>
C文件的编译、链接和运行指令
查看>>
bootstrap Modal的简单笔记
查看>>
统计一串字符串中连续相同元素的个数
查看>>
奋斗例子——>从1.5k到18k, 一个程序员的5年成长之路
查看>>
python2.x之list和tunple及dict
查看>>
后缀表达式太有才了
查看>>