2024每日刷题(一零四)
Leetcode—807. 保持城市天际线
实现代码
class Solution {
public:
int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) {
int n = grid.size();
vector<int> row(n);
vector<int> col(n);
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
row[i] = max(row[i], grid[i][j]);
col[j] = max(col[j], grid[i][j]);
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
ans += min(row[i], col[j]) - grid[i][j];
}
}
return ans;
}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!