Leetcode 598 Range Addition II
class Solution {
public :
int maxCount(int m, int n, vector <vector <int > > & ops) {
vector <int > colMatrix(n,0 );
vector <vector <int > > zeroMatrix(m,colMatrix);
int maxCount = 0 ;
int row = 0 ;
int col = 0 ;
for (auto oneRow : ops)
{
row = oneRow[0 ];
col = oneRow[1 ];
for (int i = 0 ;i < row;i ++)
{
for (int j = 0 ;j < col;j ++)
zeroMatrix[i][j] ++;
}
}
for (int i = 0 ;i < m;i ++)
{
for (int j = 0 ;j < n;j ++)
{
if (zeroMatrix[i][j] == zeroMatrix[0 ][0 ])
maxCount ++;
}
}
return maxCount;
}
int maxCount2(int m, int n, vector <vector <int > > & ops) {
if (ops.empty())
return m*n;
int row = ops[0 ][0 ];
int col = ops[0 ][1 ];
for (auto oneRow : ops)
{
row = min(row,oneRow[0 ]);
col = min(col,oneRow[1 ]);
}
return row * col;
}
};