当前进度: 10/150
题目来源:力扣1094题、力扣1109题
解题思路:B站讲解
这两个题目均为 查分数组问题,具体讲解,请看B站讲解
1094. 拼车
class Solution:
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
a = [0]* 1001
flag = True
for list_ in trips:
if list_[0] > capacity:
return False
else:
a[list_[1]-1] += list_[0]
a[list_[2]-1] -= list_[0]
for i in range(1,len(a)):
a[i] += a[i-1]
if a[i] > capacity:
flag = False
break
return flag
1109. 航班预订统计
class Solution:
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
b = [0] * (n+1)
for list_ in bookings:
b[list_[0]-1] += list_[2]
b[list_[1]] -= list_[2]
for i in range(1,len(b)):
b[i] += b[i-1]
return b[:n]