leetcode 598. Range Addition II
LeetCode II range
2023-09-14 09:11:53 时间
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.
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.
class Solution(object): def maxCount(self, m, n, ops): """ :type m: int :type n: int :type ops: List[List[int]] :rtype: int """ x, y = m, n for a,b in ops: x = min(x, a) y = min(y, b) return x*y
相关文章
- ☆打卡算法☆LeetCode 205. 同构字符串 算法解析
- LeetCode笔记:Weekly Contest 306
- LeetCode周赛289,太考验手速,我落败了……
- LeetCode 122. 买卖股票的最佳时机 II
- 秀到起飞!LeetCode官方推出算法面试指导手册(代码版)限时开源
- 前端工程师leetcode算法面试必备-简单的二叉树
- 太全了!字节总监总结240道算法LeetCode刷题笔记
- leetcode刷题(123)——63. 不同路径 II
- 【刷题day07】LeetCode(力扣)每日一刷。[876. 链表的中间结点][142. 环形链表 II][121. 买卖股票的最佳时机]
- leetcode刷题(126)——1289. 下降路径最小和 II
- 用Js怒刷LeetCode_2023-02-27
- leetcode_两数之和
- LeetCode | 有效的括号
- LeetCode - #63 不同路径 II
- 用javascript分类刷leetcode--双指针(图文视频讲解)
- LeetCode-16-最接近的三数之和
- LeetCode-338-比特位计数