leetcode807

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode807相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) {
        //找出每一行的最大值
        const int N = 50;
        int ROW_HEIGHT[N];
        int COL_HEIGHT[N];
        int MIX_HEIGHT[N][N];
        for (int i = 0; i < grid.size(); i++)
        {
            int max_height = INT_MIN;
            for (int j = 0; j < grid[0].size(); j++)
            {
                max_height = max(max_height, grid[i][j]);
            }
            ROW_HEIGHT[i] = max_height;
        }

        //找出每一列的最大值
        for (int j = 0; j < grid[0].size(); j++)
        {
            int max_height = INT_MIN;
            for (int i = 0; i < grid.size(); i++)
            {
                max_height = max(max_height, grid[i][j]);
            }
            COL_HEIGHT[j] = max_height;
        }
        //每一个值,不能超过 min(所在行的最大值,所在列的最大值)
        int sum = 0;
        for (int i = 0; i < grid.size(); i++)
        {
            for (int j = 0; j < grid[0].size(); j++)
            {
                sum += min(ROW_HEIGHT[i], COL_HEIGHT[j]) - grid[i][j];
            }
        }
        return sum;
    }
};

 

以上是关于leetcode807的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] 807. Max Increase to Keep City Skyline

python leetcode练习(807 Max Increase to Keep City Skyline)

LeetCode 807. Max Increase to Keep City Skyline

Leetcode 807. Max Increase to Keep City Skyline

LeetCode - 807. 保持城市天际线 - Java

LeetCode 807. 保持城市天际线 / 630. 课程表 III(贪心+优先队列)/ 851. 喧闹和富有(拓扑排序)