LeetCode Solutions
598. Range Addition II
Time: $O(N)$, where $N = |\texttt{ops}|$ Space:
class Solution {
public:
int maxCount(int m, int n, vector<vector<int>>& ops) {
int minY = m;
int minX = n;
for (const vector<int>& op : ops) {
minY = min(minY, op[0]);
minX = min(minX, op[1]);
}
return minX * minY;
}
};
class Solution {
public int maxCount(int m, int n, int[][] ops) {
int minY = m;
int minX = n;
for (int[] op : ops) {
minY = Math.min(minY, op[0]);
minX = Math.min(minX, op[1]);
}
return minX * minY;
}
}
class Solution:
def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:
minY = m
minX = n
for y, x in ops:
minY = min(minY, y)
minX = min(minX, x)
return minX * minY