[LeetCode&Python] Problem 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?
Example:
Input: grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]
Output: 35
Explanation:
The grid is:
[ [3, 0, 8, 4],
[2, 4, 5, 7],
[9, 2, 6, 3],
[0, 3, 1, 0] ] The skyline viewed from top or bottom is: [9, 4, 8, 7]
The skyline viewed from left or right is: [8, 7, 9, 3] The grid after increasing the height of buildings without affecting skylines is: gridNew = [ [8, 4, 8, 7],
[7, 4, 7, 7],
[9, 4, 8, 7],
[3, 3, 3, 3] ]
Notes:
1 < grid.length = grid[0].length <= 50.- All heights
grid[i][j]are in the range[0, 100]. - All buildings in
grid[i][j]occupy the entire grid cell: that is, they are a1 x 1 x grid[i][j]rectangular prism.
The key point for this problem is to reverse the matrix.
class Solution:
def maxIncreaseKeepingSkyline(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
rowMax=[max(r) for r in grid]
columnMax=[max(c) for c in zip(*grid)] result=0 for i in range(len(grid)):
for j in range(len(grid[0])):
result+=min(rowMax[i],columnMax[j])-grid[i][j] return result
[LeetCode&Python] Problem 807. Max Increase to Keep City Skyline的更多相关文章
- Leetcode 807 Max Increase to Keep City Skyline 不变天际线
Max Increase to Keep City Skyline In a 2 dimensional array grid, each value grid[i][j] represents th ...
- LeetCode #807. Max Increase to Keep City Skyline 保持城市天际线
https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/ 执行用时 : 3 ms, 在Max Increase to Ke ...
- LC 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 the ...
- 【LeetCode】807. Max Increase to Keep City Skyline 解题报告(Python &C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode】807. Max Increase to Keep City Skyline
Description In a 2 dimensional array grid, each value grid[i][j] represents the height of a building ...
- Leetcode 807. Max Increase to Keep City Skyline
class Solution(object): def maxIncreaseKeepingSkyline(self, grid): """ :type grid: Li ...
- [LeetCode&Python] Problem 485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- [LeetCode] Max Increase to Keep City Skyline 保持城市天际线的最大增高
In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located the ...
- [Swift]LeetCode807. 保持城市天际线 | Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j]represents the height of a building located ther ...
随机推荐
- MongoDB(课时17 更新函数)
3.4.3 数据更新操作 MongoDB数据存的是副本数据, 最终的数据还要保存在传统的数据库里,所以如果关系型数据库里数据变了,最好的方法是删除里面的MongoDB数据重新插入. 在MongoDB里 ...
- [ios]关于gps以及坐标系
参考:http://mobile.51cto.com/iphone-387413.htm 美国GPS使用的是WGS84的坐标系统,以经纬度的形式来表示地球平面上的某一个位置,这应该是国际共识.但在我国 ...
- 【备档】客户端自动化(主Android Appium + python
之前做分享写的文档,备档~ 0.移动客户端自动化简介 客户端自动化测试的本质 定位对象 · 操作对象 · 校验对象 对象的定位应该是自动化测试的核心,要想操作.校验一个对象,首先应该识别这个对象. 一 ...
- [.NET开发] C#实现剪切板功能
C#剪切板 Clipboard类 我们现在先来看一下官方文档的介绍 位于:System.Windows.Forms 命名空间下 Provides methods to place data on an ...
- LeetCode--136--只出现一次的数字
问题描述: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 示例 1: ...
- 49 BOM 和DOM
一.BOM window 对象 1.确认,输入, window.alert(123) // 弹框 let ret = window.confirm("是否删除") / ...
- laravel时间判断
$now = Carbon::now(); if ($now >= '2019-01-02') { }
- OAF点击事件对页面组件的Required属性不验证
在实际的需求中,OAF页面上很多字段设置了Required=YES,但是我们在点击某些按钮的时候,并不希望浏览器对其进行验证,可以通过设置 Disable Server Side Validation ...
- oracle EBS grant 您不具有执行当前操作的足够权限。请与您的系统管理员联系。
解决方式1: Set the profiles of the below three to 'None' 设置以下三个配置文件为无 FND_VALIDATION_LEVELFND 验证层 FND_FU ...
- OC self注意事项
#import <Foundation/Foundation.h> @interface Person : NSObject - (void)test; + (void)test; - ( ...