C++ Find the Overlapped Area (O(n) time and O(1) space)

  • 0

    In this case, find the minimum of left/right for each element in ops to form the overlapped area. If such one doesn't exist, return m*n for all "0" case.

    class Solution {
        int maxCount(int m, int n, vector<vector<int>>& ops) {
            auto left = INT_MAX;
            auto right = INT_MAX;
            for(auto&& element : ops){
                left = std::min(left, element[0]);
                right = std::min(right, element[1]);
            return (left != INT_MAX && right != INT_MAX ) ? left*right : m*n;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.