【扫描线】LeetCode 1094. 拼车
题目链接
思路
与 【扫描线】LeetCode 253. 会议室 II 思路一致
代码
class Solution {
public boolean carPooling(int[][] trips, int capacity) {
int[] temp = new int[1000 + 3];
for(int[] trip : trips){
temp[trip[1]] += trip[0];
temp[trip[2]] -= trip[0];
}
int sum = 0;
int maxPopulation = 0;
for(int population : temp){
sum += population;
maxPopulation = Math.max(maxPopulation, sum);
}
return maxPopulation <= capacity;
}
}