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 ...
随机推荐
- vue访问外部接口设置代理,解决跨域(vue-cli3.0)
vue-cli3.0搭建的项目,平时访问内部接口配置了拦截器,今天需要调用天气预报的外部接口,发现跨域问题,通过配置代理解决. 1.在vue.config.js中配置代理 module.exports ...
- 如何设置移动端的tab栏
这是添加tab栏的代码: { "id": "tabBar1", "st ...
- SQLServer死锁查询
--查询死锁 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys ...
- 关于windows服务器配置
#我是用的window service2008系统,在配置服务器时由于是用php进行搭建 #首先我安装好phpstudy,通过服务器ip访问,显示了个helloworld,我查看了phpstudy里的 ...
- 从1到n整数中1出现的次数(整数中1出现的次数)
题目 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.AC ...
- 线程工具类 - CountDownLatch(倒计时器)
CountDownLatch官方文档 一.原理 CountDownLatch是一个非常实用的多线程控制工具类.Count Down在英文中意为倒计时,Latch意为门闩,可以简单的将CountDown ...
- python tkinter画圆
x0=150 #圆心横坐标 y0=100 #圆心纵坐标 canvas.create_oval(x0-10,y0-10,x0+10,y0+10) #圆外矩形左上角与右下角坐标 canv ...
- php对象转数组的函数
关于php中想让对象以数组的形式访问,这时候就需要使用到get_object_vars()函数了.先来介绍一下这个函数. 官方文档是这样解释的: 1 array get_object_vars ( o ...
- 小陈现有2个任务A,B要完成,每个任务分别有若干步骤如下 一道网上没啥题解的难题(至少我是这么觉得的)
小陈现有2个任务A,B要完成,每个任务分别有若干步骤如下:A=a1->a2->a3,B=b1->b2->b3->b4->b5.在任何时候,小陈只能专心做某个任务的一 ...
- jquery ajax请求回调
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...