[LeetCode]598. Range Addition II

来源:互联网 发布:如何设置数据库子符集 编辑:程序博客网 时间:2024/06/05 07:10

[LeetCode]598. Range Addition II

题目描述

这里写图片描述

思路

筛选重复加最多的区域
即ops数组中的最小值,得到行列相乘即可

代码

#include <iostream>#include <vector>#include <algorithm>using namespace std;class Solution {public:    int maxCount(int m, int n, vector<vector<int>>& ops) {        int resRow = m, resCol = n;        for (vector<int> vec : ops) {            resRow = min(resRow, vec[0]);            resCol = min(resCol, vec[1]);        }        return resRow * resCol;    }};int main() {    Solution s;    vector<vector<int>> ops = { {3, 3}, {2, 2} };    cout << s.maxCount(3, 3, ops) << endl;    system("pause");    return 0;}