[抄题]:

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. 【解题报告】[动态规划]-PID69 / 过河卒

    原题地址:http://www.rqnoj.cn/problem/69 解题思路: 用DP[i][j]表示到达(i,j)点的路径数,则 DP[0][0]=1 DP[i][j]=DP[i-1][j]+D ...

  2. 剑指offer-第四章解决面试题思路(字符串的排序)

    题目:输入一个字符串,打印出该字符串的全排列. 思路:将整个字符串分成两部分,第一部分为一个字符,将该字符和该字符后面的字符(直到最后一个字符)依次交换,确定第一个字符:然后固定第一个字符,将后面的字 ...

  3. 【策略】一致性Hash算法

    转载请说明出处:http://blog.csdn.net/cywosp/article/details/23397179     一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT) ...

  4. 探秘VB.net中的shared与static

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/huyuyang6688/article/details/28230345        简单了解了一 ...

  5. 在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解决,谢谢!

    在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解 ...

  6. https配置指导

    为了使Apache支持https访问,系统需要安有apache.openssl.mod_ssl.so 证书申请 https://ninghao.net/blog/4449 安装证书时 安装编译open ...

  7. linux 下SPI通信注意事项(待续)

    一.2台Linux设备之间使用SPI通信 1.标准Linux只支持Master 模式.但是可以在驱动中修改为Slave模式: 2.硬件SPI可能支持Slave模式,也可能不支持.这个要提前确认好: 3 ...

  8. git 本地文件里内容 操作记录

    本地环境文件合并分支(以下的都分别 commit提交了的) [一.分支[追加] 和 [新增] 新信息 合并主线  情景] 分支内容: dr.find_element_by_id("su&qu ...

  9. JS中有几种数据类型分别是哪几种

    number,string,boolean,null,undefined,object

  10. Linux - 对文件和目录的权限管理

    对文件的权限管理 ls -l,也可以用 ll 命令查看文件权限的相关信息 第一列“-rw-r--r--.”为权限信息,权限信息的最后一个点表示为在安全环境下创建的 第二列“1”为硬链接数,第三列“ro ...