当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- JWT-JSON WEB TOKEN
- 数据库-当前读与快照读
- On weak network test of special test
- Luogu p1460 [usaco2.1] healthy Holstein cows
- Nodejs realizes the third-party login of Weibo
- Win10 cannot operate (delete, cut) files
- Database - current read and snapshot read
- 把el-tree选中的数组转换为数组对象
- Summary of anomaly detection methods
- F - true liars (category and search set +dp)
猜你喜欢
[postman] test script writing and assertion details
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
JWT-JSON WEB TOKEN
Application of Lie group in gtsam
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
Digital triangle model acwing 1015 Picking flowers
联合索引的左匹配原则
[postman] collections - run the imported data file of the configuration
P问题、NP问题、NPC问题、NP-hard问题详解
What are the test sites for tunnel engineering?
随机推荐
Thoughts on data security (Reprint)
Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
【微信小程序】搭建开发工具环境
数学三大核心领域概述:代数
Manhattan distance sum - print diamond
Amazon Engineer: eight important experiences I learned in my career
【API接口工具】postman-界面使用介绍
Configuring OSPF GR features for Huawei devices
把el-tree选中的数组转换为数组对象
GTSAM中ISAM2和IncrementalFixedLagSmoother说明
Embedded point test of app
Nodejs realizes the third-party login of Weibo
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
【无App Push 通用测试方案
Seven imperceptible truths in software testing
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
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
[wechat applet] build a development tool environment
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)