-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path463.cpp
More file actions
27 lines (26 loc) · 802 Bytes
/
463.cpp
File metadata and controls
27 lines (26 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Daily 18.4.2024
// 463. Island Perimeter
// https://leetcode.com/problems/island-perimeter/submissions/1235557233/
class Solution {
public:
int islandPerimeter(vector<vector<int>>& grid) {
int score = 0;
int n = grid.size();
int m = grid[0].size();
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(grid[i][j]){
// left
if(j < 1 || !grid[i][j-1]) score++;
// right
if(j >= m-1 || !grid[i][j+1]) score++;
// up
if(i < 1 || !grid[i-1][j]) score++;
// down
if(i >= n-1 || !grid[i+1][j]) score++;
}
}
}
return score;
}
};