当前位置:网站首页>模拟卷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,如果有错请留言,我看到了会修改的!谢谢!
边栏推荐
- G - Supermarket
- ESP32 ESP-IDF看门狗TWDT
- 【Tera Term】黑猫带你学TTL脚本——嵌入式开发中串口自动化神技能
- Postman核心功能解析-参数化和测试报告
- Accélération de la lecture vidéo de l'entreprise
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- Pat (Grade B) 2022 summer exam
- Testing of web interface elements
- 使用Nacos管理配置
- PAT(乙级)2022年夏季考试
猜你喜欢
![[web security] nodejs prototype chain pollution analysis](/img/c5/256ab30e796f0859387585873cee8b.jpg)
[web security] nodejs prototype chain pollution analysis

D - How Many Answers Are Wrong

Configuring OSPF GR features for Huawei devices

LeetCode 729. 我的日程安排表 I

GTSAM中李群的運用

Customize the gateway filter factory on the specified route

Digital triangle model acwing 1015 Picking flowers

数字三角形模型 AcWing 1015. 摘花生

Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin

IDEA 新UI使用
随机推荐
Function of activation function
数据库-当前读与快照读
【Postman】Collections-运行配置之导入数据文件
[postman] collections - run the imported data file of the configuration
Web界面元素的测试
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
职场进阶指南:大厂人必看书籍推荐
Significance of unit testing
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
G - Supermarket
[C language] qsort function
技术分享 | 常见接口协议解析
Manage configuration using Nacos
對數據安全的思考(轉載)
【API接口工具】postman-界面使用介绍
GTSAM中李群的運用
Hypothesis testing learning notes
MPLS test report
Gtest之TEST宏的用法
Software test interview questions - Test Type