LeetCode 729. My Calendar I

Problem Statement


struct MyCalendar {
events: Vec<Vec<i32>>
}


/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl MyCalendar {

fn new() -> Self {
MyCalendar {
events: vec![]
}
}

fn book(&mut self, start: i32, end: i32) -> bool {
if self.events.len() == 0 {
self.events.push(vec![start, end]);
return true;
}

for e in &self.events {
let (ss, ee) = (e[0], e[1]);
if start < ee && end > ss {
return false;
}
}

self.events.push(vec![start, end]);
return true;
}
}

/**
* Your MyCalendar object will be instantiated and called as such:
* let obj = MyCalendar::new();
* let ret_1: bool = obj.book(start, end);
*/