这道题首先意思是,横着切几刀,竖着切几刀。然后形成了若干个区域,问这些区域中最大的面积是多少。
AC!
python3
class Solution:
def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:
horizontalCuts = sorted(horizontalCuts)
verticalCuts = sorted(verticalCuts)
hs = horizontalCuts[0]
vs = verticalCuts[0]
for l in range(1, len(horizontalCuts)):
hs = max(hs, horizontalCuts[l] - horizontalCuts[l-1])
for v in range(1, len(verticalCuts)):
vs = max(vs, verticalCuts[v] - verticalCuts[v-1])
hs = max(hs, h - horizontalCuts[-1])
vs = max(vs, w - verticalCuts[-1])
return (hs % (10 ** 9 + 7) * vs % (10 ** 9 + 7)) % (10 ** 9 + 7)