Java Exercise

807. 保持城市天际线

java 复制代码
class Solution {
    public int maxIncreaseKeepingSkyline(int[][] grid) {
        int n = grid.length;
        int[] rowMax = new int[n];
        int[] colMax = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                rowMax[i] = Math.max(rowMax[i], grid[i][j]);
                colMax[j] = Math.max(colMax[j], grid[i][j]);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                ans += Math.min(rowMax[i], colMax[j]) - grid[i][j];
            }
        }
        return ans;
    }
相关推荐
泽虞13 小时前
《C++程序设计》笔记p4
linux·开发语言·c++·笔记·算法
Sammyyyyy13 小时前
Go与C# 谁才更能节省内存?
java·golang·c#
峥嵘life13 小时前
Android16 应用代码新特性
java·开发语言·学习·安全
Monkey-旭13 小时前
Android 注解完全指南:从基础概念到自定义实战
android·java·kotlin·注解·annotation
运维帮手大橙子13 小时前
算法相关问题记录
算法
Roye_ack13 小时前
【项目实战 Day5】springboot + vue 苍穹外卖系统(Redis + 店铺经营状态模块 完结)
java·spring boot·redis·学习·mybatis
JIngJaneIL14 小时前
记账本|基于SSM的家庭记账本小程序设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家庭记账本小程序
Ting-yu14 小时前
Nginx快速入门
java·服务器·前端·nginx
小虎l14 小时前
李兴华-JavaWEB就业编程实战
java