LeetCode #807. Max Increase to Keep City Skyline 保持城市天际线
https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/
执行用时 : 3 ms, 在Max Increase to Keep City Skyline的Java提交中击败了95.31% 的用户 内存消耗 : 37.7 MB, 在Max Increase to Keep City Skyline的Java提交中击败了92.13% 的用户
最直接的思路:
- 获取矩阵的每一行最大值和每一列最大值
- 根据上述最大值来“提高”建筑
class Solution {
public int maxIncreaseKeepingSkyline(int[][] grid) {
int result = 0;
int rowSize = grid.length;
// rowMax 每行最大数值
int[] rowMax = new int[rowSize]; int colSize = grid[0].length;
// colMax 每列最大数值
int[] colMax = new int[colSize]; int i = 0;
int j = 0; for (i = 0; i < rowSize; i++) {
rowMax[i] = 0;
for (j = 0; j < colSize; j++) {
if (grid[i][j] > rowMax[i]) {
rowMax[i] = grid[i][j];
}
}
} for (j = 0; j < colSize; j++) {
colMax[j] = 0;
for (i = 0; i < rowSize; i++) {
if (grid[i][j] > colMax[j]){
colMax[j] = grid[i][j];
}
}
} for (i = 0; i < rowSize; i++) {
for (j = 0; j < colSize; j++) {
if (rowMax[i] > colMax[j]) {
result += colMax[j] - grid[i][j];
} else {
result += rowMax[i] - grid[i][j];
}
}
} return result;
}
}
LeetCode #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
class Solution(object): def maxIncreaseKeepingSkyline(self, grid): """ :type grid: Li ...
- [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 ...
- 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&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 the ...
- 【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 ...
- [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 ...
- BZOJ1628: [Usaco2007 Demo]City skyline
1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 256 Solved: 210[Su ...
随机推荐
- JavaScript基础9——操作DOM树
appendChild()方法:添加子节点到末尾 类似于剪切粘贴的效果 insertBefore(newNode, oldNode)方法:在某个节点之前插入一个节点 newNode为要插入的节点, ...
- 如何在Linux下手动编译安装gcc
如果可以通过apt来安装的话,尽量不要手工编译了,手工编译是最后的选择.用apt安装,只需要输入一条命令: sudo apt-get install gcc 手工编译的话,gcc和其他软件包存在如下的 ...
- shell 搜索指定目录下所有 jar 文件生成csv文件
虽说比较简单,但希望分享给大家.按需求改成想找的:例如txt,xls 等. 脚本名 扫描的路径 文件名 testFind.sh / testFind.txt (如果未配置环境变量 ./testFi ...
- 多线程AQS
参考: AQS原理分析 https://blog.csdn.net/javazejian/article/details/75043422 重入读写锁原理分析 https://blog.csdn.ne ...
- 对react的研究0
对react的研究1.class HelloMessage extends React.Component { render() { return ( <div> Hello {this. ...
- LeetCode--053--最大子序和(java)
给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 ...
- DELPHI FMX 同时使用LONGTAP和TAP
在应用到管理图标时,如长按显示删除标志,单击取消删除标志.在FMX的手势管理中,只有长按LONGTAP,点击TAP则是单独的事件,不能在同事件中管理.在执行LONGTAP后,TAP也会被触发,解决方 ...
- Feign调用远程服务报错:Caused by: java.lang.IllegalStateException: Method getMemberInfo not annotated with HTTP method type (ex. GET, POST)
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ord ...
- 8.为什么IntelliJ IDEA首次加载比较慢
double shift 很快,是有缓存,和快速索引 这面这二个文件,配置会缓存:会越来越在,
- SQL Server查询使用键查找时锁申请及释放顺序
当然看的过程中,其实自己有个疑问: 对于键查找这类查询,会申请哪些锁,锁申请和释放的顺序是怎样的? 准备 备注:测试表仍然使用高兄文中创建的测试表testklup 在开始之前,使用dbcc ind 命 ...