Easy-10
来源:互联网 发布:yandex优化怎么做 编辑:程序博客网 时间:2024/05/16 04:29
leetcode 463. Island Perimeter
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.
Example:
[[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:
AC:
int islandPerimeter(int** grid, int gridRowSize, int gridColSize) {
int num1=0;
int sum=0;
int a,b,c,d;
for(int i=0;i<gridRowSize;i++)
{
for(int j=0;j<gridColSize;j++)
{
if(grid[i][j]==1)
{
sum+=1;
a=0;
if(i-1>=0)
{
a+=grid[i-1][j];
}
b=0;
if(j-1>=0)
{
b+=grid[i][j-1];
}
c=0;
if(i+1<gridRowSize)
{
c+=grid[i+1][j];
}
d=0;
if(j+1<gridColSize)
{
d+=grid[i][j+1];
}
num1+=a+b+c+d;
}
}
}
return sum*4-num1;
}
- Easy-10
- Leetcode--easy系列10
- easy
- Easy
- Easy-题目10:217. Contains Duplicate
- Easy 10 Search Insert Position(35)
- LeetCode-Easy刷题(10) Search Insert Position
- Easy Assembler Shell v5.0.7.10 by DeepSoftware
- Easy way for 16, 8 , 2 decimal switch 10 decimal.
- Easy way for 10 decimal switch 16 decimal
- 10 Easy Image Hover Effects You Can Copy and Paste
- 10 Easy Steps to a Complete Understanding of SQL
- easy ui 左侧 resize 没办法控制在10以下
- 16进制转10进制(最easy的做法)
- 5-10 Saving James Bond - Easy Version (25分)
- The Easy Way to Setup PostgreSQL 10 Logical Replication
- Easy Plugs
- easy problem
- Unity切换场景淡入淡出效果
- 厉害了我的哥
- 嵌入式Linux驱动——SPI子系统解读(三)
- unity3d VR手柄射线拾取,投掷,发射可拿去的物体
- 阿里云服务器如何设置IPV6通过IOS/Appstore的审核
- Easy-10
- 几种常见的编码格式
- Android-网络框架04Retrofit2.0+RxJava
- 《java设计模式》之装饰者设计模式
- HTML5微数据初识
- Caffe学习系列(1):安装配置ubuntu14.04+cuda7.5+caffe+cudnn
- Android dex文件64k限制解决办法
- Oracle常用记录
- 电商平台如何接入快递鸟电子面单API?