-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-calendar-i.rs
49 lines (43 loc) · 1.04 KB
/
my-calendar-i.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
struct MyCalendar {
date: Vec<(i32, 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 { date: vec![] }
}
fn book(&mut self, start: i32, end: i32) -> bool {
for i in self.date.iter() {
if i.0 < end && start < i.1 {
return false;
}
}
self.date.push((start, end));
true
}
}
/**
* Your MyCalendar object will be instantiated and called as such:
* let obj = MyCalendar::new();
* let ret_1: bool = obj.book(start, end);
*/
fn main() {
let mut my = MyCalendar::new();
println!("{}", my.book(10, 20));
println!("{}", my.book(15, 25));
println!("{}", my.book(20, 30));
}
#[cfg(test)]
mod tests {
use crate::MyCalendar;
#[test]
fn test() {
let mut my = MyCalendar::new();
assert!(my.book(10, 20));
assert!(!my.book(15, 25));
assert!(my.book(20, 30));
}
}