当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- Database - current read and snapshot read
- [ram IP] introduction and experiment of ram IP core
- 数学三大核心领域概述:几何
- Overview of three core areas of Mathematics: geometry
- Linux regularly backs up MySQL database
- Application of Lie group in gtsam
- 调用链监控Zipkin、sleuth搭建与整合
- IPv6 comprehensive experiment
- Isam2 operation process
- 误差的基本知识
猜你喜欢

10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
![[postman] the monitors monitoring API can run periodically](/img/9e/3f6150290b868fc1160b6b01d0857e.png)
[postman] the monitors monitoring API can run periodically

isam2运行流程

F - true liars (category and search set +dp)
![[postman] collections configuration running process](/img/09/bcd9fd6379fa724671ffd09278442e.png)
[postman] collections configuration running process

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

LeetCode 731. 我的日程安排表 II

IP day 16 VLAN MPLS configuration

技术分享 | 常见接口协议解析

Application of Lie group in gtsam
随机推荐
nodejs实现微博第三方登录
SQLMAP使用教程(三)实战技巧二
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
Web界面元素的测试
properties文件
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
多线程应用的测试与调试
通过修改style设置打印页样式
JWT-JSON WEB TOKEN
把el-tree选中的数组转换为数组对象
Properties file
【C语言】qsort函数
Réflexions sur la sécurité des données (réimpression)
自定义指定路由上的Gateway过滤器工厂
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
【eolink】PC客户端安装
對數據安全的思考(轉載)
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference