Skip to content

598. Range Addition II 👎

  • Time: $O(N)$, where $N = |\texttt{ops}|$
  • Space:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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;
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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;
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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