Skip to content

Commit dce846c

Browse files
authored
Create 1094-car-pooling.js
1 parent 426ba0a commit dce846c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

1094-car-pooling.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @param {number[][]} trips
3+
* @param {number} capacity
4+
* @return {boolean}
5+
*/
6+
const carPooling = function(trips, capacity) {
7+
let stops = new Array(1001).fill(0)
8+
for (let t of trips) {
9+
stops[t[1]] += t[0]
10+
stops[t[2]] -= t[0]
11+
}
12+
for (let i = 0; capacity >= 0 && i < 1001; ++i) capacity -= stops[i]
13+
return capacity >= 0
14+
}

0 commit comments

Comments
 (0)