标签:sky ons min += 最大值 grid bsp etc leetcode
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; } };
标签:sky ons min += 最大值 grid bsp etc leetcode
原文地址:https://www.cnblogs.com/asenyang/p/9752070.html