博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 598. Range Addition II
阅读量:6219 次
发布时间:2019-06-21

本文共 1146 字,大约阅读时间需要 3 分钟。

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 = 3operations = [[2,2],[3,3]]Output: 4Explanation: 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        """        x, y = m, n        for a,b in ops:            x = min(x, a)            y = min(y, b)        return x*y

 

转载地址:http://spoja.baihongyu.com/

你可能感兴趣的文章
iOS 7 & iOS 6适配问题
查看>>
《C++数据结构-快速拾遗》 手写链表
查看>>
hdu2068 RPG的错排 组合数/递推
查看>>
jar 文件不能运行
查看>>
小工具?不,这是小工具的集合!
查看>>
CAVLC算法解析
查看>>
12 在微服务集群中使用Zuul
查看>>
Python登陆人人网
查看>>
Exchange 2010 打补丁的顺序
查看>>
平方和与倒数和
查看>>
【乱码】乱码整理
查看>>
python基础之模块一
查看>>
RabbitMQ的几种应用场景
查看>>
跨域之URL
查看>>
第三周周报
查看>>
王思祺2015080360030的第一次作业最终版
查看>>
windows下mysql 5.7版本中修改编码为utf-8的方法
查看>>
UEFI系统安装U盘的制作方式
查看>>
自增和自减操作符
查看>>
3_主流部署方式介绍-Django+mod_wsgi+Apache
查看>>