1465. Max Area After Horizontal and Vertical Cuts
Question
You are given a rectangular cake of size
h x w
and two arrays of integershorizontalCuts
andverticalCuts
where:
horizontalCuts[i]
is the distance from the top of the rectangular cake to thei<sup>th</sup>
horizontal cut and similarly, andverticalCuts[j]
is the distance from the left of the rectangular cake to thej<sup>th</sup>
vertical cut.Return the maximum area of a piece of cake after you cut at each horizontal and vertical position provided in the arrays
horizontalCuts
andverticalCuts
. Since the answer can be a large number, return this modulo10<sup>9</sup><span> </span>+ 7
.
Solution
先排序,记录两次切割之间的距离的最大值。
最后同样需要比较蛋糕的总尺寸和最后一次切割的距离。
返回宽度和长度的最大值的乘积即可。
注意:两个int整数相乘会溢出,max需要记录为long类型。
Code
1 | class Solution { |
1465. Max Area After Horizontal and Vertical Cuts
https://xuanhe95.github.io/2022/07/02/1465-Max-Area-After-Horizontal-and-Vertical-Cuts/