MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / diffs

Method diffs

matrix/count_islands_in_matrix.py:20–27  ·  view source on GitHub ↗
(self, i: int, j: int, visited: list[list[bool]])

Source from the content-addressed store, hash-verified

18 )
19
20 def diffs(self, i: int, j: int, visited: list[list[bool]]) -> None:
21 # Checking all 8 elements surrounding nth element
22 row_nbr = [-1, -1, -1, 0, 0, 1, 1, 1] # Coordinate order
23 col_nbr = [-1, 0, 1, -1, 1, -1, 0, 1]
24 visited[i][j] = True # Make those cells visited
25 for k in range(8):
26 if self.is_safe(i + row_nbr[k], j + col_nbr[k], visited):
27 self.diffs(i + row_nbr[k], j + col_nbr[k], visited)
28
29 def count_islands(self) -> int: # And finally, count all islands.
30 visited = [[False for j in range(self.COL)] for i in range(self.ROW)]

Callers 1

count_islandsMethod · 0.95

Calls 1

is_safeMethod · 0.95

Tested by

no test coverage detected