807. Max Increase to Keep City Skyline
In a 2 dimensional array grid
, each value grid[i][j]
represents the height of a building located there. We are allowed to increase the height of any number of buildings, by any amount (the amounts can be different for different buildings). Height 0 is considered to be a building as well.
At the end, the "skyline" when viewed from all four directions of the grid, i.e. top, bottom, left, and right, must be the same as the skyline of the original grid. A city's skyline is the outer contour of the rectangles formed by all the buildings when viewed from a distance. See the following example.
What is the maximum total sum that the height of the buildings can be increased?
解题要点:
以下为保底解法,时间速度极慢。首先找出从上往下看,从左往右看的最大值,分别存入两个数组。遍历整个grid时,一个个看是否达到了最大值,如没有则往返回值里加1。
Last updated
Was this helpful?