Super easy Java solution using TreeMap


  • 9
    S
    public class Solution {
        public int minMeetingRooms(Interval[] intervals) {
            Map<Integer, Integer> map = new TreeMap<Integer, Integer>(); // Sort Key based on nature order
            for (Interval i : intervals) {
                if (map.containsKey(i.start)) {
                    map.put(i.start, map.get(i.start)+1);
                } else {
                    map.put(i.start, 1);
                }
                if (map.containsKey(i.end)) {
                    map.put(i.end, map.get(i.end)-1);
                } else {
                    map.put(i.end, -1);
                }
            }
            int maxRoom = 0; int curRoom = 0;
            for (int i : map.keySet()) {
                maxRoom = Math.max(maxRoom, curRoom += map.get(i));
            }
            return maxRoom;
        }
    }

Log in to reply
 

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