LeetCode 732 my schedule Table III

732. My schedule Table III

topic

Here Insert Picture Description
Here Insert Picture Description

Thinking

Boundary recording, scanning, looking for the maximum.

Code

class MyCalendarThree {
public:
    map<int,int> mp;
    MyCalendarThree() {

    }
    
    int book(int start, int end) {
        mp[start]+=1;
        mp[end]-=1;

        int ans=0,sum=0;
        for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
        {
            sum+=it->second;
            if(ans<sum) ans=sum;
        }
        return ans;
    }
};

/**
 * Your MyCalendarThree object will be instantiated and called as such:
 * MyCalendarThree* obj = new MyCalendarThree();
 * int param_1 = obj->book(start,end);
 */
Published 173 original articles · won praise 6 · views 40000 +

Guess you like

Origin blog.csdn.net/shidonghang/article/details/103175062
Recommended