File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ // Car Pooling
2+ impl Solution {
3+ pub fn car_pooling ( trips : Vec < Vec < i32 > > , capacity : i32 ) -> bool {
4+ let mut s = vec ! [ 0 ; 1001 ] ;
5+ for t in trips. iter ( ) {
6+ s[ t[ 1 ] as usize ] += t[ 0 ] ;
7+ s[ t[ 2 ] as usize ] -= t[ 0 ] ;
8+ }
9+ let mut x = 0 ;
10+ for i in 0 ..1001 {
11+ x += s[ i] ;
12+ if x > capacity { return false ; }
13+ }
14+ true
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ // Corporate Flight Bookings
2+ impl Solution {
3+ pub fn corp_flight_bookings ( bookings : Vec < Vec < i32 > > , n : i32 ) -> Vec < i32 > {
4+ let n = n as usize ;
5+ let mut s = vec ! [ 0 ; n+1 ] ;
6+ for b in bookings. iter ( ) {
7+ s[ b[ 0 ] as usize - 1 ] += b[ 2 ] ;
8+ s[ b[ 1 ] as usize ] -= b[ 2 ] ;
9+ }
10+ let mut ans = vec ! [ 0 ; n] ;
11+ let mut x = 0 ;
12+ for i in 0 ..n {
13+ x += s[ i] ;
14+ ans[ i] = x;
15+ }
16+ ans
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments