leetcode732+calender|||+hash map判断end点最多的值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/84189361

https://leetcode.com/problems/my-calendar-iii/description/

class MyCalendarThree {
public:
    map<int, int> m;
    int maximum = 0;
    MyCalendarThree() {
        
    }
    
    int book(int start, int end) {
        int k = 0;
        m[start] -= 1;//start点是出度
        m[end] +=1;//end点是入度 -1
        for(auto i= m.begin(); i!=m.end(); i++){
            k += i->second;//记录点都是出度的值
            if(maximum<k) maximum = k;
        }
        return maximum;
    }
};



/**
 * Your MyCalendarThree object will be instantiated and called as such:
 * MyCalendarThree obj = new MyCalendarThree();
 * int param_1 = obj.book(start,end);
 */

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/84189361