#598

Range Addition II

pupil · 455 · lc easy +26 · verified · 58.4% accepted · 1,035 likes · top 55%

play →

Description

You have an m x n matrix of zeros. Each operation ops[i] = [ai, bi] adds 1 to every cell M[x][y] where 0 <= x < ai and 0 <= y < bi. After applying all operations, count and return how many cells hold the maximum value.

Example 1:

Input: m = 3, n = 3, ops = [[2,2],[3,3]]
Output: 4
Explanation: The maximum integer in M is 2, and there are four of it in M. So return 4.

Example 2:

Input: m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]
Output: 4

Example 3:

Input: m = 3, n = 3, ops = []
Output: 9

Code

1
2
3