use std::collections::BTreeMap;
struct MyCalendarThree { events: BTreeMap<i32, i32> }
impl MyCalendarThree {
fn new() -> Self { MyCalendarThree { events: BTreeMap::new() } }
fn book(&mut self, start: i32, end: i32) -> i32 { self.events.entry(start).or_insert(0); self.events.entry(end).or_insert(0); *self.events.get_mut(&start).unwrap() += 1; *self.events.get_mut(&end).unwrap() -= 1; let (mut count, mut ans) = (0, 0); for (_k, v) in &self.events { count += *v; ans = std::cmp::max(count, ans); } return ans; } }
|