Skip to content

Commit 65480bb

Browse files
authored
Create Solution.java
1 parent 397de8d commit 65480bb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public boolean carPooling(int[][] trips, int capacity) {
3+
int[] cnt = new int[1001];
4+
for (int[] trip : trips) {
5+
cnt[trip[1]] += trip[0];
6+
cnt[trip[2]] -= trip[0];
7+
}
8+
if (cnt[0] > capacity) return false;
9+
for (int i = 1; i < 1001; ++i) {
10+
cnt[i] += cnt[i - 1];
11+
if (cnt[i] > capacity) {
12+
return false;
13+
}
14+
}
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)