Skip to content

Commit ce2a1ee

Browse files
committed
Create 0463-island-perimeter.kt
1 parent 324cd74 commit ce2a1ee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

kotlin/0463-island-perimeter.kt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
fun islandPerimeter(grid: Array<IntArray>): Int {
3+
if(grid.size == 0 || grid[0].size == 0)
4+
return 0
5+
var res = 0
6+
for(i in 0..grid.size-1){
7+
for(j in 0..grid[0].size-1){
8+
if(grid[i][j]==1){
9+
res += 4
10+
if(i > 0 && grid[i-1][j]==1)
11+
res -= 2
12+
if(j > 0 && grid[i][j-1]==1)
13+
res -= 2
14+
}
15+
}
16+
}
17+
return res
18+
}
19+
}

0 commit comments

Comments
 (0)