[抄题]:

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. python学习之aop装饰模式

    实际开发过程当中可能要对某些方法或者流程做出改进,添加监控,添加日志记录等所以我们要去改动已有的代码,自己的或者别人的,但改动后测试不周会引发不可控的异常,aop 模式解决了这类问题引发重复代码大量积 ...

  2. POJ1797 Heavy Transportation

    解题思路:典型的Kruskal,不能用floyed(会超时),上代码: #include<cstdio> #include<cstring> #include<algor ...

  3. HDU - 6178:Monkeys (贪心&树上最大匹配输&输入优化)

    There is a tree having N vertices. In the tree there are K monkeys (K <= N). A vertex can be occu ...

  4. HihoCoder - 1615矩阵游戏II(贪心)

    矩阵游戏II 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个NxN的整数矩阵,小Hi每次操作可以选择两列,将这两列中的所有数变成它的相反数. 小Hi可以进行任意 ...

  5. 5,基于关系和超链接的 API

    Tutorial 5: Relationships & Hyperlinked APIs At the moment relationships within our API are repr ...

  6. Yet another A + B

    time limit per test 0.25 s memory limit per test 64 MB input standard input output standard output Y ...

  7. zTree返回的菜单列表中根据权限打勾

    需求:管理员登录后台后可以为角色添加菜单,同时要能看到该角色已经拥有的菜单. 想法一:刚开始写的时候很迷茫,因为我们有可能会为该角色增加别的菜单,所以不能只加载该角色已经拥有的菜单,只加载该角色的菜单 ...

  8. asp.net 操作共享目录文件

    背景: 服务器A为程序服务器,服务器B为文件服务器.服务器A的程序需要修改删除服务器B的文件. 实现方式:采用虚拟目录映射 操作步骤: 1.在服务器A与服务器B建立相同账号和密码的windows用户 ...

  9. 数据库中通过group by找出表中的重复数据

    有时候在做数据割接时会碰到数据插入失败的情况,大部分都是导出的数据中存在重复导致的.我们可以通过查询语句带分组条件来确认是否有重复数据.例如我现在有表 t_wlf_info,其中有个 username ...

  10. oracle 11g r2 rac到单实例的dg

    oracle 11g r2 rac到单实例的dg 1 主备环境说明 rac环境--primary CentOS release 6.5 (Final)hostname rac1 rac2ip 10.* ...