Skip to content

Commit 196758f

Browse files
authored
Update 1094-car-pooling.js
1 parent 3c76811 commit 196758f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

1094-car-pooling.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {number[][]} trips
3+
* @param {number} capacity
4+
* @return {boolean}
5+
*/
6+
const carPooling = function(trips, capacity) {
7+
const arr = Array(1001).fill(0)
8+
for(const [num, s, e] of trips) {
9+
arr[s] += num
10+
arr[e] -= num
11+
}
12+
for(let i = 1; i < 1001; i++) {
13+
arr[i] += arr[i - 1]
14+
}
15+
16+
for(let e of arr) {
17+
if(e > capacity) return false
18+
}
19+
return true
20+
};
21+
22+
// another
23+
124
/**
225
* @param {number[][]} trips
326
* @param {number} capacity

0 commit comments

Comments
 (0)