Leetcode

Range Addition II

  • Time:O(N), where N = |\texttt{ops}|
  • Space:Space:

C++

class Solution {
 public:
  int maxCount(int m, int n, vector<vector<int>>& ops) {
    int minY = m;
    int minX = n;

    for (const auto& op : ops) {
      minY = min(minY, op[0]);
      minX = min(minX, op[1]);
    }

    return minX * minY;
  }
};

JAVA

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;
  }
}

Python

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