MCPcopy
hub / github.com/HuberTRoy/leetCode / numIslands

Method numIslands

Array/NumberOfIslands.py:39–80  ·  view source on GitHub ↗

:type grid: List[List[str]] :rtype: int

(self, court)

Source from the content-addressed store, hash-verified

37 (x+1, y))
38
39 def numIslands(self, court):
40 """
41 :type grid: List[List[str]]
42 :rtype: int
43 """
44 fans_groups = []
45 x = 0
46 y = 0
47 if not court:
48 return 0
49
50 x_length = len(court[0])
51 y_length = len(court)
52
53 def helper(x, y):
54 Xy = self.makeXY(x, y)
55 for i in Xy:
56 try:
57 if i[1] < 0 or i[0] < 0:
58 continue
59
60 if court[i[1]][i[0]] == '1':
61 court[i[1]][i[0]] = '0'
62 t = helper(i[0], i[1])
63 except IndexError:
64 continue
65 else:
66 return 1
67
68
69 for y in range(y_length):
70 for x in range(x_length):
71 if court[y][x] == '1':
72 court[y][x] = '0'
73 fans_groups.append(helper(x, y))
74
75
76
77 if not fans_groups:
78 return 0
79
80 return len(fans_groups)
81

Callers

nothing calls this directly

Calls 1

helperFunction · 0.70

Tested by

no test coverage detected