https://leetcode.cn/problems/corporate-flight-bookings/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
var corpFlightBookings = function(bookings, n) { let R=new Array(n+1).fill(0) for(let booking of bookings){ let [first,last,seats]=booking R[first]+=seats if(last+1<R.length){ R[last+1]-=seats } } for(let i=2;i<n+1;i++){ R[i]+=R[i-1] } R.shift() return R };
|