Java实现 LeetCode 598 范围求和 II(最小值相乘)
598. 范围求和 II
给定一个初始元素全部为 0,大小为 m*n 的矩阵 M 以及在 M 上的一系列更新操作。
操作用二维数组表示,其中的每个操作用一个含有两个正整数 a 和 b 的数组表示,含义是将所有符合 0 <= i < a 以及 0 <= j < b 的元素 M[i][j] 的值都增加 1。
在执行给定的一系列操作后,你需要返回矩阵中含有最大整数的元素个数。
示例 1:
输入:
m = 3, n = 3
operations = [[2,2],[3,3]]
输出: 4
解释:
初始状态, M =
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]
执行完操作 [2,2] 后, M =
[[1, 1, 0],
[1, 1, 0],
[0, 0, 0]]
执行完操作 [3,3] 后, M =
[[2, 2, 1],
[2, 2, 1],
[1, 1, 1]]
M 中最大的整数是 2, 而且 M 中有4个值为2的元素。因此返回 4。
注意:
m 和 n 的范围是 [1,40000]。
a 的范围是 [1,m],b 的范围是 [1,n]。
操作数目不超过 10000。
class Solution {
//因为每次都是从0开始,找到最小的x坐标和y坐标,相乘即可
public int maxCount(int m, int n, int[][] ops) {
int min1 = m, min2 = n;
for(int[] l: ops){
min1 = Math.min(min1,l[0]);
min2 = Math.min(min2,l[1]);
}
return min1*min2;
}
}
Java实现 LeetCode 598 范围求和 II(最小值相乘)的更多相关文章
- Java for LeetCode 212 Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- Java for LeetCode 210 Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- Java for LeetCode 059 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- Java for LeetCode 126 Word Ladder II 【HARD】
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- LeetCode 598. Range Addition II (范围加法之二)
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
- [LeetCode] 598. Range Addition II 范围相加之二
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
- Java实现 LeetCode 63 不同路径 II(二)
63. 不同路径 II 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在 ...
- Java实现 LeetCode 40 组合总和 II(二)
40. 组合总和 II 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的每个数字在 ...
- Java for LeetCode 229 Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...
随机推荐
- 【Linux系列汇总】小白博主的嵌入式Linux实战快速进阶之路(持续更新)
我把之前在学习嵌入式Linux和工作中遇到问题和相关经验等,一起整理到这里,方便自己查阅和学习,温故而知新,如果能帮助到您,请帮忙点个赞: 本文的宗旨 嵌入式Linux 的项目通常需要一个团队来开发, ...
- uCOS2014.1.10
uC/OS-Ⅱ任务的结构有两种:一种是无限循环结构:另一种是只执行一次的程序结构.若采用只执行一次的程序结构,就要用任务删除函数来实现. uC/OS-Ⅱ进行任务的管理是从调用启动函数OSStart() ...
- C# -- WebClient自动获取web页面编码并转换
C# -- WebClient自动获取web页面编码并转换 抽个时间,写篇小文章,最近有个朋友,用vb开发一个工具,遇到WebClient获取的内容出现乱码,可惜对vb不是很熟悉,看了几分钟vb的语法 ...
- 【Effective Java】第二章-创建和销毁对象——1.考虑用静态工厂方法代替构造器
静态工厂方法的优点: 可以赋予一个具有明确含义的名称 可以复用唯一实例,不必每次新建 可以返回原实例类型的子类对象 可以在返回泛型实例时更加简洁 缺点: 类如果不含有共有的或者受保护的构造器,就不能被 ...
- 使用windows(win7和win10),最好用chocolatey
Win10平台使用PowerShell命令行choco来安装所需开源软件. 步骤如下: 打开Chocolatey 官方网站,The package manager for windows,这很巨硬. ...
- 使用gitHub和git进行团队合作开发
1.创建仓库(项目)-----组织者(Leader)和团队成员 1)Leader在gitHub上创建一个新组织(New organization),然后邀请成员加入 2)Leader在该组织下创建一个 ...
- java 字符串转为list
List<String> idList = Arrays.asList(irIds.split(","));
- Centos 安装 docker 和 docker-compose
一.docker安装 1.卸载旧版本 sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ d ...
- SVN强制添加备注
1.进入仓库project1/hooks目录,找到pre-commit.tmpl文件 cp pre-commit.tmpl pre-commit 2.编辑pre-commit文件, 将: $SVNLO ...
- C# 数据操作系列 - 16 SqlSugar 完结篇
0. 前言 前一篇我们详细的介绍了SqlSugar的增删改查,那些已经满足我们在日常工程开发中的使用了.但是还有一点点在开发中并不常用,但是却非常有用的方法.接下来让我们一起来看看还有哪些有意思的内容 ...