class Solution {
public:
int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) {
//找出每一行的最大值
const int N = ;
int ROW_HEIGHT[N];
int COL_HEIGHT[N];
int MIX_HEIGHT[N][N];
for (int i = ; i < grid.size(); i++)
{
int max_height = INT_MIN;
for (int j = ; j < grid[].size(); j++)
{
max_height = max(max_height, grid[i][j]);
}
ROW_HEIGHT[i] = max_height;
} //找出每一列的最大值
for (int j = ; j < grid[].size(); j++)
{
int max_height = INT_MIN;
for (int i = ; i < grid.size(); i++)
{
max_height = max(max_height, grid[i][j]);
}
COL_HEIGHT[j] = max_height;
}
//每一个值,不能超过 min(所在行的最大值,所在列的最大值)
int sum = ;
for (int i = ; i < grid.size(); i++)
{
for (int j = ; j < grid[].size(); j++)
{
sum += min(ROW_HEIGHT[i], COL_HEIGHT[j]) - grid[i][j];
}
}
return sum;
}
};

leetcode807的更多相关文章

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

随机推荐

  1. bzoj2152: 聪聪可可 树分治

    sb树分治 /************************************************************** Problem: 2152 User: walfy Lang ...

  2. java读取PHP接口数据的实现方法(四)

    PHP文件: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3 ...

  3. 从0开始springboot

    http://412887952-qq-com.iteye.com/blog/2291500

  4. Django中CSS加载background url('')问题

    Django中CSS加载background url('')问题   在django中, 默认CSS中如果有 background url('images/a.jpg') 这类的属性,会被django ...

  5. CF 272E Dima and Horses 染色,dfs 难度:2

    http://codeforces.com/problemset/problem/272/E 把仇恨关系想象为边, 因为度只能为0,1,2,3,所以有以下几种 0,1 直接放即可 2: 有(1,1), ...

  6. pos 和 AnsiPos

    PropsClearList[I]的值是 用户=个人 R := AnsiPos(Equal_sign, PropsClearList[I]); ShowMessage( IntToStr( R));/ ...

  7. 在JavaScript中进行文件处理,第一部分:基础

    译注:原文是<JavaScript高级程序设计>的作者Nicholas Zakas写的,本翻译纯属为自己学习而做,仅供参考.原文链接:这里 很多年前,我在一次Goole面试被问到,如何在w ...

  8. 201621123005《Java程序设计》第十三次实验总结

    <Java程序设计>第十三周实验总结 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主 ...

  9. react 拖拽排序---原生

    定义css, 两个动画 .drag-up { -webkit-animation: dragup ease 0.2s 1; animation: dragup ease 0.2s 1; -webkit ...

  10. 爸妈才是最好的避孕药--------"北大状元拉黑父母事件的一些感想"

    今天看了这么一篇文章,地址:  http://mini.eastday.com/mobile/180131180318786.html <北大状元拉黑父母6年:你敢恨爸妈,可你敢原谅他们吗?&g ...