Untitled
unknown
plain_text
a year ago
605 B
6
Indexable
class Solution {
public boolean carPooling(int[][] trips, int capacity) {
int[] arr = new int[1001];
for(int[] trip : trips){
int noOfPassengers = trip[0];
int from = trip[1];
int to = trip[2];
arr[from] += noOfPassengers;
arr[to] -= noOfPassengers;
}
int curCapacity = 0;
for(int i = 0; i < 1001; i++){
curCapacity += arr[i];
if(curCapacity > capacity) return false;
}
return true;
}
}Editor is loading...
Leave a Comment