算法笔记: 力扣#598 范围求和 ii

问题描述


解法


分析

Python 实现

1
2
3
4
5
6
7
8
9
10
11
12
class (object):
def maxCount(self, m, n, ops):
"""
:type m: int
:type n: int
:type ops: List[List[int]]
:rtype: int
"""
for a, b in ops:
m = min(m, a)
n = min(n, b)
return m * n

Java 实现

1
2
3
4
5
6
7
8
9
class {
public int maxCount(int m, int n, int[][] ops) {
for(int[] op : ops){
m = m < op[0] ? m : op[0];
n = n < op[1] ? n : op[1];
}
return m*n;
}
}

时间复杂度

O(n).

空间复杂度

O(1).

链接


598. Range Addition II
598. 范围求和 II
(English version) Algorithm Notes: Leetcode#598 Range Addition II