Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9ace9b

Browse files
solved: 463. Island Perimeter
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent b0d9d70 commit d9ace9b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
impl Solution {
2+
pub fn island_ erimeter(grid: Vec<Vec<i32>>) -> i32 {
3+
let mut perimeter = 0;
4+
5+
for i in 0..grid.len() {
6+
for j in 0..grid[i].len() {
7+
if grid[i][j] == 1 {
8+
perimeter += 4;
9+
10+
if i != 0 && grid[i - 1][j] == 1 {
11+
perimeter -= 2;
12+
}
13+
if j != 0 && grid[i][j - 1] == 1 {
14+
perimeter -= 2;
15+
}
16+
}
17+
}
18+
}
19+
20+
perimeter
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /