The stupidest way


  • 0
    T
    class MyCalendar {
    	Map<Integer, Integer> map = new HashMap<>();
    	public MyCalendar() {
    	}
    	public boolean book(int start, int end) {
    		if (map.size() == 0) {
    			map.put(start, end);
    			return true;
    		}
    		int i = 0;
    		for (Integer key : map.keySet()) {
    			if (start < key && end <= key || start > key && start >= map.get(key)) {
    				++i;
    			}
    			if (i == map.size()) {
    				map.put(start, end);
    				return true;
    			}
    		}
    
    		return false;
    	}
    }
    

Log in to reply
 

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