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

Method maxAreaOfIsland

Array/MaxAreaOfIsland.py:38–79  ·  view source on GitHub ↗

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

(self, court)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

helperFunction · 0.70

Tested by

no test coverage detected