当前位置: 首页 > news >正文

Java LeetCode 练习

        807. 保持城市天际线

package JavaExercise20241004;import java.util.Arrays;public class JavaExercise {public static void main(String[] args) {int[][] array = {{3,0,8,4},{2,4,5,7},{9,2,6,3},{0,3,1,0}};Solution solution = new Solution();System.out.println(solution.maxIncreaseKeepingSkyline(array));}
}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;}
}


http://www.mrgr.cn/news/42840.html

相关文章:

  • Qt自定义控件:雷达扫描
  • 155. 最小栈
  • java相关新技术
  • isinstance()学习
  • 《计算机原理与系统结构》学习系列
  • idea创建springboot模块
  • 在 ArkTS 网络请求中,重新封装一下 http 模块
  • pWnOS2.0 靶机渗透( cms 渗透,php+mysql 网站渗透,密码碰撞)
  • 业务封装与映射 -- 映射方式
  • 排序算法之选择排序
  • 分布式学习02-CAP理论
  • Linux进程控制(2)(进程程序替换1)
  • 【3D目标检测】激光雷达和相机联合标定(一)——ROS同步解包
  • python学习记录6
  • 堆排序算法的原理与应用
  • 基于Keras的U-Net模型在图像分割与计数中的应用
  • 企业级数据备份一般都是怎么做的?来唠唠嗑
  • pytest(三)——参数化@pytest.mark.parametrize
  • node_exporter使用textfile collector收集业务数据
  • PostgreSQL 创建账号与数据库:从连接到权限配置的完整指南