-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem1094.java
More file actions
38 lines (38 loc) · 1.04 KB
/
problem1094.java
File metadata and controls
38 lines (38 loc) · 1.04 KB
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
class Solution {
public boolean carPooling(int[][] trips, int capacity) {
/*
int numPeople = 0;
int max = Integer.MIN_VALUE;
for(int i = 0; i < trips.length; i++){
max = (trips[i][2] > max)? trips[i][2] : max;
}
for(int j = 0; j < max; j++){
for(int k = 0; k < trips.length; k++){
if(j == trips[k][1]){
numPeople += trips[k][0];
}
if(j == trips[k][2]){
numPeople -= trips[k][0];
}
}
if(numPeople > capacity){
return false;
}
}
return true;
*/
int arr[] = new int[1001];
for(int[] i : trips){
arr[i[1]] += i[0];
arr[i[2]] -= i[0];
}
int numPeople = 0;
for(int i = 0 ; i < arr.length; i++){
numPeople += arr[i];
if(numPeople > capacity){
return false;
}
}
return true;
}
}