Skip to content

Commit 17947d7

Browse files
committed
Create 1465.切割后面积最大的蛋糕.js
1 parent 4c8d476 commit 17947d7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number} h
3+
* @param {number} w
4+
* @param {number[]} horizontalCuts
5+
* @param {number[]} verticalCuts
6+
* @return {number}
7+
*/
8+
var maxArea = function(h, w, horizontalCuts, verticalCuts) {
9+
horizontalCuts.sort((a, b) => a - b);
10+
verticalCuts.sort((a, b) => a - b);
11+
horizontalCuts.unshift(0);
12+
horizontalCuts.push(h);
13+
verticalCuts.unshift(0);
14+
verticalCuts.push(w);
15+
16+
let maxH = 0;
17+
for (let i = 1; i < horizontalCuts.length; i++) {
18+
maxH = Math.max(maxH, horizontalCuts[i] - horizontalCuts[i - 1]);
19+
}
20+
21+
let maxV = 0;
22+
for (let i = 1; i < verticalCuts.length; i++) {
23+
maxV = Math.max(maxV, verticalCuts[i] - verticalCuts[i - 1]);
24+
}
25+
26+
return maxH * maxV % (10 ** 9 + 7);
27+
};

0 commit comments

Comments
 (0)