598. Range Addition II 矩阵的范围叠加
[抄题]:
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 矩阵的范围叠加的更多相关文章
- 【leetcode_easy】598. Range Addition II
problem 598. Range Addition II 题意: 第一感觉就是最小的行和列的乘积即是最后结果. class Solution { public: int maxCount(int ...
- [LeetCode] 598. Range Addition II 范围相加之二
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
- LeetCode: 598 Range Addition II(easy)
题目: Given an m * n matrix M initialized with all 0's and several update operations. Operations are r ...
- 598. Range Addition II
Given an m * n matrixMinitialized with all0's and several update operations. Operations are represen ...
- LeetCode 598. Range Addition II (范围加法之二)
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
- [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 ...
- 【LeetCode】598. Range Addition II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【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 ...
- [LeetCode] Range Addition II 范围相加之二
Given an m * n matrix M initialized with all 0's and several update operations. Operations are repre ...
随机推荐
- MyBatis典型的错误org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
XXXmapper.java(接口) XXXmapper.xml(结果集映射) //此两个文件要在统一包下,且xml中的namespace是唯一的,为了区分须写成 该xml的全路径
- 《DSP using MATLAB》示例Example7.20
代码: M = 51; alpha = (M-1)/2; Dw = 2*pi/M; l = 0:M-1; wl = Dw*l; T1 = j*0.39; k1 = 0:floor((M-1)/2); ...
- Windows 系统定时自动重启
1.创建新文本并输入 shutdown -r -t 0 保存成.bat文件 2.创建系统任务计划 2.1 在开始中打开[任务计划程序] 2.2 新建创建任务计划目录 2.3 在新目录下新建任务计划即可 ...
- django配置静态文件
django配置静态文件 参考文章链接:http://blog.csdn.net/hireboy/article/details/8806098
- Linux修改数据库的访问权限
以下方法可以帮助你解决这个问题了,下面的语句功能是,建立一个用户为monitor密码admin权限为和root一样.允许任意主机连接.这样你可以方便进行在本地远程操作数据库了. CREATE USER ...
- 为什么 I2C(IIC)需要上拉电阻
源鑫问: I2C时钟线和数据线为什么要接上拉电阻? 因为 I2C 的 IO 是开漏的,所以需要上拉电阻. 延伸: 之前 hippo曾经说过有人将 IO 设置为 PP,可能会烧 IO. 之前以为 I2C ...
- FastAdmin 在线命令生成时出错的分析
FastAdmin 在线命令生成时出错的分析 出错现象 版本环境 FastAdmin 版本:1.0.0.20180806_beta 在线命令插件版本:1.0.3 分析 2018-08-13 16:12 ...
- STM32GPIO管脚设置
(1)GPIO_Mode_AIN 模拟输入 (2)GPIO_Mode_IN_FLOATING 浮空输入(3)GPIO_Mode_IPD 下拉输入 (4)GPIO_Mode_IPU 上拉输入 (5)GP ...
- Amoeba mysql读写分离搭建及介绍
Amoeba mysql读写分离搭建及介绍 推荐: http://blog.chinaunix.net/uid-20639775-id-154600.html
- 整数a整数b
namespace ConsoleApplication6{ class Program { static void Main(string[] args) { while (true) { Cons ...