# 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()的括号总是忘记，导致编译错误，这个要时刻注意。

#### python--leetcode463. Island Perimeter

2017-09-29 20:39:31

#### leetcode 463 Island Perimeter C++

2016-11-27 23:19:11

#### [leetcode: Python]463. Island Perimeter

2017-05-16 18:26:53

#### [leetcode] 463. Island Perimeter 解题报告

2016-11-25 12:34:35

#### 【leetcode】463. Island Perimeter【E】

2016-11-21 13:06:13

#### Leetcode 463. Island Perimeter 求岛的周长 解题报告

2016-11-21 21:48:10

#### 463. Island Perimeter

2016-11-20 18:55:38

#### LeetCode 463. Island Perimeter(Java)

2017-01-21 11:52:02

#### 463. Island Perimeter （5月29日）

2018-05-30 00:13:23

#### leetcode- Island Perimeter

2016-11-30 16:48:41