Given an m * n matrixMinitialized with all0's and several update operations.

Operations are represented by a 2D array, and each operation is represented by an array with twopositiveintegersaandb, which meansM[i][j]should beadded by onefor all0 <= i < aand0 <= j < b.

You need to count and return the number of maximum integers in the matrix after performing all the operations.

Example 1:

Input:
m = 3, n = 3
operations = [[2,2],[3,3]]
Output: 4
Explanation:
Initially, M =
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]] After performing [2,2], M =
[[1, 1, 0],
[1, 1, 0],
[0, 0, 0]] After performing [3,3], M =
[[2, 2, 1],
[2, 2, 1],
[1, 1, 1]] So the maximum integer in M is 2, and there are four of it in M. So return 4.

Note:

  1. The range of m and n is [1,40000].
  2. The range of a is [1,m], and the range of b is [1,n].
  3. The range of operations size won't exceed 10,000.
给定一个M*N 的矩阵和一组操作符operations,每一次将[0,0]—>operation[a,b]的数值加1,求操作后矩阵最大整数的数量。

这不就是求操作符operations中,第一维度和第二维度最小值的乘积么?a*b

class Solution {
public int maxCount(int m, int n, int[][] ops) {
if (ops == null || ops.length == 0) {
return m * n;
}
int row = Integer.MAX_VALUE, col = Integer.MAX_VALUE;
for(int op[] : ops)
{
row = Math.min(row,op[0]);
col = Math.min(col,op[1]);
}
return row * col;
}
}
 
 
 
 

598. Range Addition II的更多相关文章

  1. 【leetcode_easy】598. Range Addition II

    problem 598. Range Addition II 题意: 第一感觉就是最小的行和列的乘积即是最后结果. class Solution { public: int maxCount(int ...

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

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

  3. 598. Range Addition II 矩阵的范围叠加

    [抄题]: Given an m * n matrix M initialized with all 0's and several update operations. Operations are ...

  4. LeetCode: 598 Range Addition II(easy)

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

  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&Python] Problem 598. Range Addition II

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

  7. 【LeetCode】598. Range Addition II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. 【leetcode】598. Range Addition II

    You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i ...

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

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

随机推荐

  1. [欧拉路径]Play on Words UVA10129

    传送门:   UVA - 10129 题目大意: 给定一些单词(可能会重复出现),判断单词是否能排成一个序列,前提是单词的最后一个字母与下一个单词的第一个字母相同.输出"The door c ...

  2. TFboy养成记 简单小程序(Variable & placeholder)

    学习参考周莫烦的视频. Variable:主要是用于训练变量之类的.比如我们经常使用的网络权重,偏置. 值得注意的是Variable在声明是必须赋予初始值.在训练过程中该值很可能会进行不断的加减操作变 ...

  3. C#学习笔记---数据库连接与异常

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  4. 关于Could not resolve dependencies for project

    异常:Could not resolve dependencies for project 思路:网上提出的方案思路都是把相互依赖的项目导入到本地仓库中. 目前一劳永逸的方法是:将<packag ...

  5. 常用接口简析2---IComparable和IComparer接口的简析

    常用接口的解析(链接) 1.IEnumerable深入解析 2.IEnumerable.IEnumerator接口解析 3.IList.IList接口解析 默认情况下,对象的Equals(object ...

  6. hdu 1068 Girls and Boys 最大独立点集 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1068 思路: 求一集合满足,两两之间没有恋爱关系 思路: 最大独立点集=顶点数-最大匹配数 这里给出的 ...

  7. CCS模块库文件的生成与使用

    在一个大的项目中,为了便于管理,有时需要将一个模块封装为库文件,并可以在项目中使用. 图表 1 项目 步骤如下: 1.右键-->new-->CCS Project 图表 2 新建ccs p ...

  8. iOS 提交AppStore不出现构建的版本

    提交App Store不出现构建的版本 Xcode版本:8.0 近日往App Store上跟新一个版本,提交了好几次,built号增加了好几个,上传每次都成功了,但是在iTunes Contact上一 ...

  9. ChromeExtension那些事儿

    Chrome Extension是什么呢? 简而言之,就是Chrome扩展,它是基于Chrome浏览器的,我们可以理解它为一个独立运行在Chrome浏览器下的APP,当然核心编程语言就是JavaScr ...

  10. MFC控件实现视频“暂停” “播放”循环

    问static有什么作用,朗朗上口,可是用起来呢 MFC"按钮"控件实现开始显示"播放",按一下之后就开始播放相关视频,并且按钮显示为"暂停" ...