File tree Expand file tree Collapse file tree 3 files changed +106
-0
lines changed
solution/0200-0299/0252.Meeting Rooms Expand file tree Collapse file tree 3 files changed +106
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,43 @@ public:
98
98
};
99
99
```
100
100
101
+ ### **Rust**
102
+
103
+ ```rust
104
+ impl Solution {
105
+ #[allow(dead_code)]
106
+ pub fn can_attend_meetings(intervals: Vec<Vec<i32>>) -> bool {
107
+ if intervals.len() == 1 {
108
+ return true
109
+ }
110
+
111
+ let mut intervals = intervals;
112
+
113
+ // Sort the intervals vector
114
+ intervals.sort_by(|lhs, rhs| {
115
+ lhs[0].cmp(&rhs[0])
116
+ });
117
+
118
+ let mut end = -1;
119
+
120
+ // Begin traverse
121
+ for p in &intervals {
122
+ if end == -1 {
123
+ // This is the first pair
124
+ end = p[1];
125
+ continue;
126
+ }
127
+ if p[0] < end {
128
+ return false;
129
+ }
130
+ end = p[1];
131
+ }
132
+
133
+ true
134
+ }
135
+ }
136
+ ```
137
+
101
138
### ** Go**
102
139
103
140
``` go
Original file line number Diff line number Diff line change @@ -73,6 +73,43 @@ public:
73
73
};
74
74
```
75
75
76
+ ### **Rust**
77
+
78
+ ```rust
79
+ impl Solution {
80
+ #[allow(dead_code)]
81
+ pub fn can_attend_meetings(intervals: Vec<Vec<i32>>) -> bool {
82
+ if intervals.len() == 1 {
83
+ return true
84
+ }
85
+
86
+ let mut intervals = intervals;
87
+
88
+ // Sort the intervals vector
89
+ intervals.sort_by(|lhs, rhs| {
90
+ lhs[0].cmp(&rhs[0])
91
+ });
92
+
93
+ let mut end = -1;
94
+
95
+ // Begin traverse
96
+ for p in &intervals {
97
+ if end == -1 {
98
+ // This is the first pair
99
+ end = p[1];
100
+ continue;
101
+ }
102
+ if p[0] < end {
103
+ return false;
104
+ }
105
+ end = p[1];
106
+ }
107
+
108
+ true
109
+ }
110
+ }
111
+ ```
112
+
76
113
### ** Go**
77
114
78
115
``` go
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ #[ allow( dead_code) ]
3
+ pub fn can_attend_meetings ( intervals : Vec < Vec < i32 > > ) -> bool {
4
+ if intervals. len ( ) == 1 {
5
+ return true
6
+ }
7
+
8
+ let mut intervals = intervals;
9
+
10
+ // Sort the intervals vector
11
+ intervals. sort_by ( |lhs, rhs| {
12
+ lhs[ 0 ] . cmp ( & rhs[ 0 ] )
13
+ } ) ;
14
+
15
+ let mut end = -1 ;
16
+
17
+ // Begin traverse
18
+ for p in & intervals {
19
+ if end == -1 {
20
+ // This is the first pair
21
+ end = p[ 1 ] ;
22
+ continue ;
23
+ }
24
+ if p[ 0 ] < end {
25
+ return false ;
26
+ }
27
+ end = p[ 1 ] ;
28
+ }
29
+
30
+ true
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments