forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (27 loc) · 717 Bytes
/
main.cpp
File metadata and controls
36 lines (27 loc) · 717 Bytes
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
/// Source : https://leetcode.com/problems/car-pooling/
/// Author : liuyubobobo
/// Time : 2019-06-22
#include <iostream>
#include <vector>
#include <map>
using namespace std;
/// Using TreeMap to record all the time events
/// Time Complexity: O(n)
/// Space Complexity: O(n)
class Solution {
public:
bool carPooling(vector<vector<int>>& trips, int capacity) {
map<int, int> map;
for(const vector<int>& trip: trips)
map[trip[1]] += trip[0], map[trip[2]] -= trip[0];
int cur = 0;
for(const pair<int, int>& p: map){
cur += p.second;
if(cur > capacity) return false;
}
return true;
}
};
int main() {
return 0;
}