当前位置:网站首页>模拟卷Leetcode【普通】1109. 航班预订统计
模拟卷Leetcode【普通】1109. 航班预订统计
2022-07-06 06:15:00 【邂逅模拟卷】
1109. 航班预订统计
这里有 n 个航班,它们分别从 1 到 n 进行编号。
有一份航班预订表 bookings ,表中第 i 条预订记录 bookings[i] = [firsti, lasti, seatsi] 意味着在从 firsti 到 lasti (包含 firsti 和 lasti )的 每个航班 上预订了 seatsi 个座位。
请你返回一个长度为 n 的数组 answer,其中 answer[i] 是航班 i 上预订的座位总数。
示例 1:
输入:bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
输出:[10,55,45,25,25]
解释:
航班编号 1 2 3 4 5
预订记录 1 : 10 10
预订记录 2 : 20 20
预订记录 3 : 25 25 25 25
总座位数: 10 55 45 25 25
因此,answer = [10,55,45,25,25]
示例 2:
输入:bookings = [[1,2,10],[2,2,15]], n = 2
输出:[10,25]
解释:
航班编号 1 2
预订记录 1 : 10 10
预订记录 2 : 15
总座位数: 10 25
因此,answer = [10,25]
提示:
1 <= n <= 2 * 104
1 <= bookings.length <= 2 * 104
bookings[i].length == 3
1 <= firsti <= lasti <= n
1 <= seatsi <= 104
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/corporate-flight-bookings
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
代码:
import time
from typing import List
class Solution:
def __init__(self):
pass
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
bookings_save = [0 for _ in range(n+2)]
for first,last,seats in bookings:
bookings_save[first]+=seats
bookings_save[last+1]-=seats
result = [bookings_save[1]]
for x in bookings_save[2:-1]:
result.append(x+result[-1])
return result
def test(data_test):
s = Solution()
return s.corpFlightBookings(*data_test)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun, data in zip(data_test[0][1::], data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[[[1,2,10],[2,3,20],[2,5,25]],5],
[[[1,2,10],[2,2,15]],2],
# [],
]
for data_test in datas:
t0 = time.time()
print('-' * 50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
备注:
GitHub:https://github.com/monijuan/leetcode_python
CSDN汇总:模拟卷Leetcode 题解汇总_卷子的博客-CSDN博客
可以加QQ群交流:1092754609
leetcode_python.utils详见汇总页说明
先刷的题,之后用脚本生成的blog,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- Eigen sparse matrix operation
- LeetCode 1200. 最小绝对差
- [postman] collections configuration running process
- GTSAM中ISAM2和IncrementalFixedLagSmoother说明
- 浅谈专项测试之弱网络测试
- Buuctf-[bjdctf2020]zjctf, but so (xiaoyute detailed explanation)
- Manage configuration using Nacos
- 黑猫带你学UFS协议第4篇:UFS协议栈详解
- Function of contenttype
- 【Postman】Monitors 监测API可定时周期运行
猜你喜欢
Overview of three core areas of Mathematics: algebra
JMeter做接口测试,如何提取登录Cookie
How to extract login cookies when JMeter performs interface testing
D - How Many Answers Are Wrong
Understanding of processes and threads
使用Nacos管理配置
Database - current read and snapshot read
LeetCode 731. 我的日程安排表 II
在uni-app中使用腾讯视频插件播放视频
Configuring OSPF GR features for Huawei devices
随机推荐
Hypothesis testing learning notes
Company video accelerated playback
把el-tree选中的数组转换为数组对象
LeetCode 739. 每日温度
Construction and integration of Zipkin and sleuth for call chain monitoring
Isam2 and incrementalfixedlagsmooth instructions in gtsam
Significance of unit testing
Nodejs realizes the third-party login of Weibo
联合索引的左匹配原则
【微信小程序】搭建开发工具环境
isam2运行流程
「 WEB测试工程师 」岗位一面总结
LeetCode 1200. 最小绝对差
Idea new UI usage
在线问题与离线问题
黑猫带你学UFS协议第4篇:UFS协议栈详解
[C language] qsort function
Detailed explanation of BF and KMP
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
【Postman】测试(Tests)脚本编写和断言详解