Back to course home
0% completed
Vote For New Content
least amount of code
kfaham
Aug 30, 2025
class Solution: def findDistinctIslandsDFS(self, matrix): sizes = set() def size(i, j): if not (0 <= i < len(matrix) and 0 <= j < len(matrix[0])) or matrix[i][j] == 0: return 0 matrix[i][j] = 0 return size(i + 1, j) + size(i - 1, j) + size(i, j + 1) + size(i, j - 1) + 1 for i in range(len(matrix)): for j in range(len(matrix[i])): if matrix[i][j] == 1: sizes.add(size(i, j)) return len(sizes)
0
0
Comments
Comments
On this page