Loading

【leetcode】598. Range Addition II

  You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.

Count and return the number of maximum integers in the matrix after performing all the operations.
  
class Solution {
public:
    int maxCount(int m, int n, vector<vector<int>>& ops) {
        
        //取所有操作的交集就是最大int number的个数 冷静思考就没问题 啊哈哈哈
        if(ops.size()==0) return m*n;
        int limit_m=m,limit_n=n;
        for(auto aa:ops)
        {
            limit_m=min(limit_m,aa[0]);
            limit_n=min(limit_n,aa[1]);
        }
        return limit_m*limit_n;
    }
};

 

  
posted @ 2021-11-19 21:33  aalanwyr  阅读(34)  评论(0编辑  收藏  举报