博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 598. Range Addition II
阅读量:5279 次
发布时间:2019-06-14

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

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.Note:The range of m and n is [1,40000].The range of a is [1,m], and the range of b is [1,n].The range of operations size won't exceed 10,000.

题目大意:给出矩阵大小,给出每次加的坐标(x,y)那么每次操作都会使(0~x,0~y)这个矩阵内的格子加1,求最大的格子的个数。

class Solution {public:    int maxCount(int m, int n, vector
>& ops) { vector
> v; if (ops.size() == 0) return m*n; int x = 100000; int y = 100000; for (int i = 0; i < ops.size(); ++i) { x = min(x, ops[i][0]); y = min(y, ops[i][1]); } return x*y; }};

转载于:https://www.cnblogs.com/pk28/p/8486767.html

你可能感兴趣的文章
【Linux】Linux 自己主动挂载NTFS格式移动硬盘
查看>>
LinbDesk --- 新的extjs4.2 desktop demo : 技术交流Q群:336584192
查看>>
Ubuntu14.04下安装ZendStudio10.6.1+SVN出现Failed to load JavaHL Library
查看>>
Wind River Linux 6 Security Profile
查看>>
Android_显示器本身被卸载应用程序
查看>>
怎样以学习单片机为契机,逐步成为优秀的project师
查看>>
Java中Integer类的方法
查看>>
“error : unknown filesystem”的解决的方法
查看>>
linux杂谈(十九):DNSserver的配置(二)
查看>>
《网络攻防》第二周作业
查看>>
关于Windows Live Writer博客同步
查看>>
linux下的C语言快速学习—计算机体系结构基础简单了解
查看>>
nextTick refs
查看>>
书写 sql 中关于 update 多表联合更新的方法
查看>>
构建高性能、高并发的JAVA应用系统
查看>>
推荐学习--《解剖PetShop》
查看>>
内置函数
查看>>
ucore lab1实验笔记
查看>>
java内部类概念
查看>>
(60)zabbix网络发现介绍Network Discovery
查看>>