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

Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a and b, which means M[i][j] should be added by one for all 0 <= i < a and 0 <= 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.

class Solution(object):
def maxCount(self, m, n, ops):
"""
:type m: int
:type n: int
:type ops: List[List[int]]
:rtype: int
"""
for o in ops:
m=min(o[0],m)
n=min(o[1],n)
return m*n

  

[LeetCode&Python] Problem 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. LeetCode: 598 Range Addition II(easy)

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

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

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

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

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

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

  8. 598. Range Addition II

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

  9. [LeetCode&Python] Problem 541. Reverse String II

    Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...

随机推荐

  1. Spring整合Hystrix

    1.添加maven依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId> ...

  2. killl prefix out macro mis mal micro -m

    1● macro 宏大,规模大   2● mis 错误,坏   3● mal 坏,错误   4● micro 小,微小  

  3. vs2015如何使用附加进程调试发布在IIS上项目

    1.如何使用附加进程调试IIS上的网站项目 1)在IIS部署一个网站项目 2)保证浏览器可访问(比如访问登陆页面) 3)在项目中LoginController断点,并在工具栏的调试找到附加到进程 4) ...

  4. linux磁盘管理 文件挂载

    文件挂载的概念 根文件系统之外的其他文件要想能够被访问,都必须通过"关联"到根文件系统上的某个系统来实现,此关联操作即为"挂载",此目录即为"挂载点& ...

  5. java⑨

    do-while,先执行一次,再判断! do{ 循环体 }while(循环条件); 经典案例: 1. 需求:    01.记录每次用户购买的商品金额! 之后进行 结账!    02.增加购买商品的数量 ...

  6. Factory,工厂设计模式,C++描述

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  7. vue安装与配置

    直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装   $ npm install vue ...

  8. Map中根据条件删除元素

    今天在写程序过程中,需要根据判断条件删除一个Map中的相应数据,我自然而然想到可以通过调用Map中的remove(Object key)函数进行删除:代码如下: public Map<Doubl ...

  9. 八. Python基础(8)--函数

    八. Python基础(8)--函数 1 ● 函数返回布尔值 注意, 自定义的函数也可以是用来作逻辑判断的, 例如内置的startswith()等函数. def check_len(x):     ' ...

  10. SQL-12 获取所有部门中当前员工薪水最高的相关信息,给出dept_no, emp_no以及其对应的salary

    题目描述 获取所有部门中当前员工薪水最高的相关信息,给出dept_no, emp_no以及其对应的salaryCREATE TABLE `dept_emp` (`emp_no` int(11) NOT ...