博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
598. Range Addition II 矩阵的范围叠加
阅读量:4356 次
发布时间:2019-06-07

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

[抄题]:

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.

 [暴力解法]:

时间分析:

空间分析:

 [优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩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;    }}
View Code

 

转载于:https://www.cnblogs.com/immiao0319/p/8987669.html

你可能感兴趣的文章
C# 中的委托和事件[转帖]
查看>>
图的遍历(bfs+dfs)模板
查看>>
angular service 进行组件通信
查看>>
linux安装Mac的默认Monaco字体
查看>>
java语言的特点
查看>>
关于动态添加iview admin路由以及刷新侧边栏
查看>>
ApplicationInsights的探测器尝鲜
查看>>
java 解析Json格式数据
查看>>
unix中的线程池技术详解
查看>>
CSS简介
查看>>
常用三大软件评价1
查看>>
MVC各层介绍使用---初步理解
查看>>
单例对象的创建与销毁
查看>>
知识点关键词(记录一下)
查看>>
国际结算业务
查看>>
嵌套循环概念
查看>>
C# 生成订单号的几种方式
查看>>
IOS开发札记
查看>>
1.2.2 OSI参考模型 上
查看>>
centos服务器设置代理上网的方法
查看>>