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% 的用户

最直接的思路:

  1. 获取矩阵的每一行最大值和每一列最大值
  2. 根据上述最大值来“提高”建筑
 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 保持城市天际线的更多相关文章

  1. 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 ...

  2. Leetcode 807. Max Increase to Keep City Skyline

    class Solution(object): def maxIncreaseKeepingSkyline(self, grid): """ :type grid: Li ...

  3. [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 ...

  4. 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 ...

  5. 【LeetCode】807. Max Increase to Keep City Skyline 解题报告(Python &C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  6. [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 ...

  7. 【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 ...

  8. [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 ...

  9. BZOJ1628: [Usaco2007 Demo]City skyline

    1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Su ...

随机推荐

  1. 【错误】Publishing to Tomcat'has encountered a problem

    tomcat 启动工程时候出现 Publishing to Tomcat'has encountered a problem错误 解决方案 之后重启tomcat 就可以正常启动了

  2. head 显示文件头部内容

    1. 命令功能 head 默认显示文件前10行内容. 2.语法格式 head option file 参数说明 参数 参数说明 -n 指定显示行数 -c 指定显示的字节数 -v 总是显示文件名的文件头 ...

  3. 前端 js javascript

    新浪SAE公共资源 推荐指数★★★ 支持https http://lib.sinaapp.com/http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3 ...

  4. Linux 查找指定内容在哪个文件中

    在实际的工作中,忘记配置项放在哪个文件中时,可借助命令来查询. eg: 1.grep -r "查询内容"  文件目录    #这样查询出来的包括文件名+内容 grep -r -l ...

  5. 【串线篇】spring boot对静态资源的映射规则

    WebMvcAutoConfiguration的内部类 WebMvcAutoConfigurationAdapter 其中ResourceProperties点进去 其中addResourceHand ...

  6. js undefined三目运算

    js ajax传值中 "id":$('#id').val(), 如果#id不存在,使用$('#id').val()||‘’,可避免向后台传入undefined

  7. Page.after

    解释: Page.after可以增加Page级的切面,触发的时机是在所拦截的对应生命周期方法执行之后,也可以拦截所有页面上发生的事件(对于要拦截的事件,在swan文件上必须显示绑定了相应事件). 方法 ...

  8. CSS中属性百分比的基准点

    1.属性百分比的基准点 1.1.基于包含块 以下的关于包含块(含块)的概念,不能简单地理解成是父元素. 如果是静态定位和相对定位,包含块一般就是其父元素.但是对于绝对定位的元素,包含块应该是离它最近的 ...

  9. Android签名机制之---签名验证过程详解

    一.前言 今天是元旦,也是Single Dog的嚎叫之日,只能写博客来祛除寂寞了,今天我们继续来看一下Android中的签名机制的姊妹篇:Android中是如何验证一个Apk的签名.在前一篇文章中我们 ...

  10. 【2019 Multi-University Training Contest 5】

    01: 02:https://www.cnblogs.com/myx12345/p/11649221.html 03: 04:https://www.cnblogs.com/myx12345/p/11 ...