[抄题]:

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.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

行列都取最小值

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O() Space complexity: O()

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

表示每次取出的是数组,op[0]表示该被取出的数组中的第0位,op[1]表示该数组中的第1位

//find min, max
for (int[] op : ops) {
row = Math.min(op[0], row);
col = Math.min(op[1], col);
}

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

370. Range Addition 就是操作数组吧

[代码风格] :

class Solution {
public int maxCount(int m, int n, int[][] ops) {
//cc
if (ops == null || ops.length == 0) return m * n; //ini:min max
int row = Integer.MAX_VALUE, col = Integer.MAX_VALUE; //find min, max
for (int[] op : ops) {
row = Math.min(op[0], row);
col = Math.min(op[1], col);
} 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. 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 matrixMinitialized with all0's and several update operations. Operations are represen ...

  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. MarkDown小技巧

    MarkDown编辑 MarkDown编辑的时候,可以直接插入HTML的编辑手法. 例如如果想要将一段话中的某一个或者某几个字设为其他颜色,但又不想将这几个字与这段话分割的时候,可以这样 你可以这样将 ...

  2. php str_pad() 用法

    $temp = str_pad("    ", 10000); for($i=0;$i<20;$i++){    echo $temp;    echo $i;    sle ...

  3. [转载] 视音频数据处理入门:RGB、YUV像素数据处理

    ===================================================== 视音频数据处理入门系列文章: 视音频数据处理入门:RGB.YUV像素数据处理 视音频数据处理 ...

  4. bzoj 5369 最大前缀和

    Written with StackEdit. Description 小\(C\)是一个算法竞赛爱好者,有一天小\(C\)遇到了一个非常难的问题:求一个序列的最大子段和. 但是小\(C\)并不会做这 ...

  5. verilog 2001中的一些新语法

    比较有用的:1,generate语句,但需注意,generate-for中变量范围是已知的确定值, generate-case,generate-if语句中变量都必须是固定的, generate必须跟 ...

  6. UVA11174 Stand in a Line

    题意 PDF 分析 \[ f(i)=f(c_1)f(c_2)\dots\times(s(i)-1)!/(s(c_1)!s(c_2)! \dots s(c_k)! )\\ f(root)=(s(root ...

  7. eclipse 中xml文件的字体改不了

    XML Editor的改不了. 修改colors & fonts里的eclipse中打开window->prefece->generation-basic 下 Text Edito ...

  8. ubuntu 环境变量配置

    1.vim /etc/environment 2.vim /etc/profile export JAVA_HOME=/opt/jdk1.6.0_45PATH=$JAVA_HOME/bin:/pub/ ...

  9. 你知道SOCKET吗

    要想理解socket首先得熟悉一下TCP/IP协议族, TCP/IP(Transmission Control Protocol/Internet Protocol)即传输控制协议/网间协议,定义了主 ...

  10. Appium+python自动化29-toast消息(亲测 ok)

    本篇转自博客:上海-悠悠 前言 appium1.5以后的版本才支持toast定位,并且 'automationName'得设置为'Uiautomator2',才能捕获到. 一. Supported P ...