-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path807.保持城市天际线.js
More file actions
37 lines (36 loc) · 780 Bytes
/
807.保持城市天际线.js
File metadata and controls
37 lines (36 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* @lc app=leetcode.cn id=807 lang=javascript
*
* [807] 保持城市天际线
*/
// @lc code=start
/**
* @param {number[][]} grid
* @return {number}
*/
var maxIncreaseKeepingSkyline = function (grid) {
const newGrid = [];
let res = 0;
for (let i = 0; i < grid.length; i++) {
const temp = [];
for (let j = 0; j < grid.length; j++) {
temp.push(grid[j][i]);
}
newGrid.push(temp);
}
for (let i = 0; i < grid.length; i++) {
for (let j = 0; j < grid.length; j++) {
let num = Math.min(Math.max(...grid[i]), Math.max(...newGrid[j]));
res += num - grid[i][j];
}
}
return res;
};
const grid = [
[3, 0, 8, 4],
[2, 4, 5, 7],
[9, 2, 6, 3],
[0, 3, 1, 0],
];
console.log(maxIncreaseKeepingSkyline(grid));
// @lc code=end