Meeting rooms II - Teeeeeebag/LeetCode GitHub Wiki

/**
 * Definition for an interval.
 * public class Interval {
 *     int start;
 *     int end;
 *     Interval() { start = 0; end = 0; }
 *     Interval(int s, int e) { start = s; end = e; }
 * }
 */
class Tuple implements Comparable<Tuple> {
    public int time;
    public boolean isStart;
    public Tuple(int t, boolean isStart){
        this.time = t;
        this.isStart = isStart;
    }
    public int compareTo(Tuple other ){
        if(this.isStart && other.isStart){
            return this.time - other.time;
        } else if (!this.isStart && !other.isStart){
            return this.time - other.time;
        } else {
            if(this.time == other.time){
                if(this.isStart){
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return this.time-other.time;
            }
        }
    }
}
public class Solution {
    public int minMeetingRooms(Interval[] intervals) {
        if(intervals.length == 0){
            return 0;
        }
        ArrayList<Tuple> tpls = new ArrayList<>();
        for (Interval interval : intervals){
            tpls.add(new Tuple(interval.start, true));
            tpls.add(new Tuple(interval.end, false));
        }
        Collections.sort(tpls);
        int maxNum = 0;
        int cnt = 0;
        for (Tuple tpl : tpls){
            if(tpl.isStart){
                ++cnt;
            } else {
                --cnt;
            }
            maxNum = Math.max(maxNum, cnt);
        }
        return maxNum;
    }
}
⚠️ **GitHub.com Fallback** ⚠️