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(最小值相乘)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Java for LeetCode 126 Word Ladder II 【HARD】

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  5. LeetCode 598. Range Addition II (范围加法之二)

    Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...

  6. [LeetCode] 598. Range Addition II 范围相加之二

    Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...

  7. Java实现 LeetCode 63 不同路径 II(二)

    63. 不同路径 II 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为"Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在 ...

  8. Java实现 LeetCode 40 组合总和 II(二)

    40. 组合总和 II 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的每个数字在 ...

  9. 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 ...

随机推荐

  1. matlab 提示 Error using mex No supported compiler or SDK was found 错误的解决办法

    在使用simulink的S-Function去调用C程序的时候,需要使用mex指令预先编译C程序,但是出现 Error using mex No supported compiler or SDK w ...

  2. linux centos7搭建redis-5.0.5

    1. 下载redis 1.1 下载地址 http://download.redis.io/releases/ 1.2 安装版本 redis-5.0.5.tar.gz 2. 安装redis 2.1 前置 ...

  3. FPGA代码优化方法和准则

  4. 基于R语言的航空公司客户价值分析

    分析航空公司现状 1.行业内竞争 民航的竞争除了三大航空公司之间的竞争之外,还将加入新崛起的各类小型航空公司.民营航空公司,甚至国外航空巨头.航空产品生产过剩,产品同质化特征愈加明显,于是航空公司从价 ...

  5. 800+Java后端经典面试题,希望你找到自己理想的Offer呀~

    前言 在茫茫的互联网海洋中寻寻觅觅,我收藏了800+道Java经典面试题,分享给你们.建议大家收藏起来,在茶余饭后拿出来读一读,以备未雨绸缪之需.另外,面试题答案的话,我打算后面慢慢完善在github ...

  6. 简单的Java实现Netty进行通信

    使用Java搭建一个简单的Netty通信例子 看过dubbo源码的同学应该都清楚,使用dubbo协议的底层通信是使用的netty进行交互,而最近看了dubbo的Netty部分后,自己写了个简单的Net ...

  7. 题解 P4296 【[AHOI2007]密码箱】

    由题意有 \(x^2\equiv 1\;mod\;n\) 对题目的公式进行变形 \(x^2-1=k\times n\) \((x+1)(x-1)=k\times n\) 由唯一分解定理,我们构造\(a ...

  8. python之模块、类、对象

    模块就像字典 字典是python中唯一映射关系,它用一个事物对应另外一个事物,也就是所谓的key->value. 模块包含一些变量和函数,可以导入,并且可以用点(·)来操作访问变量和函数. 记住 ...

  9. python 之模块引入

    模块引入: 1.同级引入 如 ac_first.py 引入ac_second.py:只需直接 import ac_second 即可 这种情况 不论是 python ac\ac_first.py 还是 ...

  10. axios请求拦截器(修改Data上的参数 ==>把data上的参数转为FormData)

    let instance = axios.create({ baseURL: 'http://msmtest.ishare-go.com', //请求基地址 // timeout: 3000,//请求 ...