deno.land / x / masx200_leetcode_test@10.6.5 / max-increase-to-keep-city-skyline / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export default function maxIncreaseKeepingSkyline(grid: number[][]): number { const n = grid.length; const row_max = Array(n).fill(0); const col_max = Array(n).fill(0);
grid.forEach((a, i) => { a.forEach((v, j) => { row_max[i] = Math.max(row_max[i], v); col_max[j] = Math.max(col_max[j], v); }); }); let ans = 0; grid.forEach((a, i) => { a.forEach((v, j) => { ans += Math.min(row_max[i], col_max[j]) - v; }); }); return ans;}
masx200_leetcode_test

Version Info

Tagged at
2 years ago