Back to course home
0% completed
Vote For New Content
Much simpler solution?
siddhantgawsane
Feb 1, 2025
I have a much simpler solution by simply counting the number of 0 edges
class Solution: def findIslandPerimeter(self, matrix): # TODO: Write your code here perimeter = 0 for i, column in enumerate(matrix): for j, elem in enumerate(column): if elem == 1: if 0 > i-1 or matrix[i-1][j] == 0: perimeter += 1 if i+1 > len(matrix)-1 or matrix[i+1][j] == 0: perimeter += 1 if 0 > j-1 or matrix[i][j-1] == 0: perimeter += 1 if j+1 > len(column)-1 or matrix[i][j+1] == 0: perimeter += 1 return perimeter
0
0
Comments
Comments
On this page