# Island Perimeter

[[0,1,0,0],
[1,1,1,0],
[0,1,0,0],
[1,1,0,0]]

class Solution {
public:
int islandPerimeter(vector<vector<int>>& grid) {
int count = 0;
int side = 0;

for (int i = 0; i < grid.size(); i++) {
for (int j = 0; j < grid[i].size(); j++) {
//cout << grid[i][j];
if (grid[i][j] == 1) {
count++;
if (j > 0) {
if (grid[i][j - 1] == 1) {
side++;
}
}
if (i > 0) {
if (grid[i - 1][j] == 1) {
side++;
}
}
if (j < grid[i].size() - 1) {
if (grid[i][j + 1] == 1) {
side++;
}
}
if (i < grid.size() - 1) {
if (grid[i + 1][j] == 1) {
side++;
}
}
}
}
}
return count * 4 - side;
}
};

1.grid.size()的括号总是忘记，导致编译错误，这个要时刻注意。

• 本文已收录于以下专栏：

## LeetCode | 463. Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen...

## 463.Island Perimeter

463. Island Perimeter 海岛周长You are given a map in form of a two-dimensional integer grid where 1 repr...

## 463. Island Perimeter

Total Accepted: 27942 Total Submissions: 49580 Difficulty: Easy Contributors: amankaraj You are ...

## leetcode 463. Island Perimeter

leetcode 算法题代码以及解决思路

## LeetCode-463. Island Perimeter (Java)

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen...
• 2017-06-07 09:17
• 119

Island Perimeter

## Leetcode学习（11）—— Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen...

## 463. Island Perimeter\242. Valid Anagram\*260. Single Number III\409. Longest Palindrome

Island Perimeter 题目描述 代码实现463. Island Perimeter题目描述You are given a map in form of a two-dimensional ...

## LeetCode之Island Perimeter

1、题目 You are given a map in form of a two-dimensional integer grid where 1 represents land and ...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)