[Java] Small change to TreeMap, only check floor entry.


  • 0
    P

    Up for making a small change to the existing TreeMap method and only check floor entries. Thanks

    class MyCalendar {
    private  TreeMap<Integer, Integer> books = new TreeMap<>();
        public MyCalendar() {
            
        }
        
        public boolean book(int start, int end) {
             java.util.Map.Entry<Integer, Integer> floor = books.floorEntry(end-1);
            if(floor != null &&floor.getValue()>start)
                return false;
            books.put(start, end);
            return true;
        }
    }
    

Log in to reply
 

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