598. Range Addition II

Given an m * n matrix M initialized with all 0's and several update operations.

Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a and b, which means M[i][j] should be added by one for all 0 <= i < a and 0 <= j < b.

You need to count and return the number of maximum integers in the matrix after performing all the operations.

Solution:

思路:找min_row, min_col, 持续缩小范围
Time Complexity: O() Space Complexity: O()

Solution Code:

public class Solution {
    public int maxCount(int m, int n, int[][] ops) {
        if (ops == null || ops.length == 0) {
            return m * n;
        }
        
        int row = Integer.MAX_VALUE, col = Integer.MAX_VALUE;
        for(int[] op : ops) {
            row = Math.min(row, op[0]);
            col = Math.min(col, op[1]);
        }
        
        return row * col;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,793评论 0 33
  • 1.问题 昨天在群里发了倡议书,虽然写的不全面也没有清晰的思路讲明白想要阐述的问题。但根据群里人的反应可能有如下问...
    秦家炎阅读 334评论 2 4
  • 这几年,极简主义的理念比较流行,经常看到公众号的推文,原本乱糟糟充满杂物的房间,通过整理收纳变得干净清爽,空无一物...
    闻人伊一阅读 2,457评论 7 37