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 ...
随机推荐
- openstack stein部署手册 5. placement
# 建立数据库用户及权限 create database placement; grant all privileges on placement.* to placement@'localhost' ...
- 获取用户真实IP:(模拟:客户端--F5--nginx--tomcat 后端获取用户真实IP)
模拟:客户端--F5--nginx--tomcat 后端获取用户真实IP 192.168.109.137 :nginx01(充当第一层代理==F5)192.168.109.138 :nginx02(二 ...
- 树——binary-tree-postorder-traversal(树的前序遍历)
问题: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given bina ...
- xml与json互转
依赖包: <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib< ...
- 装饰器模式-Decerator
一.定义 装饰器模式又叫做包装模式(Wrapper).装饰器模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案. 在以下情况下应该使用装饰器模式: 1.需要扩展一个类的功能,或给一个类增 ...
- 六、MyBatis-缓存机制
MyBatis 包含一个非常强大的查询缓存特性,它可以非常方便地配置和定制.缓存可以极大的提升查询效率.MyBatis系统中默认定义了两级缓存, 一级 缓存和 二级缓存.– 1.默认情况下,只有一级缓 ...
- flask之视图函数从前端接收数据的方法
一:从前端接收查询字符串 query-string 注意:get和post都可以在url后面添加查询字符串?a=1&b=2 测试工具:postman 1:get方式接收 视图函数 from ...
- python 按多维列表中的某一个元素位进行排序
import os,re top = os.popen("tasklist") process_list = [] split_r = r"\s+" memor ...
- DELPHI FMX 获取系统版本 ANDROID IOS通用
引用System.sysutils function getOSInfo:String; begin result:= fomrat('%s:%d.%d', TOSVersion.Name,TOSVe ...
- 编辑器直接word直接上传word里的图片
tinymce是很优秀的一款富文本编辑器,可以去官网下载.https://www.tiny.cloud 这里分享的是它官网的一个收费插件powerpaste的旧版本源码,但也不影响功能使用. http ...