将数组排序之后,进行差分,然后选择各自最大的能够元素相乘,就能得到最大的蛋糕块了。注意按照题目要求,最终结果要取余数
class Solution:
def maxArea(self, h: int, w: int, horizontalCuts: List[int], verticalCuts: List[int]) -> int:
horizontalCuts.sort()
horizontalCuts.append(h-horizontalCuts[-1])
for i in range(len(horizontalCuts)-2,0,-1):
horizontalCuts[i] = horizontalCuts[i]-horizontalCuts[i-1]
verticalCuts.sort()
verticalCuts.append(w-verticalCuts[-1])
for i in range(len(verticalCuts)-2,0,-1):
verticalCuts[i] = verticalCuts[i]-verticalCuts[i-1]
return max(horizontalCuts)*max(verticalCuts)%(1000000007)