当前位置:网站首页>Simulation volume leetcode [general] 1109 Flight reservation statistics
Simulation volume leetcode [general] 1109 Flight reservation statistics
2022-07-06 06:17:00 【Encounter simulation volume】
1109. Flight booking Statistics
Here you are n A flight , They are from 1 To n Number .
There is a flight reservation form bookings , No i Booking records bookings[i] = [firsti, lasti, seatsi] Means from firsti To lasti ( contain firsti and lasti ) Of Every flight I made a reservation on seatsi A seat .
Please return a length of n Array of answer, among answer[i] It's a flight i The total number of seats booked on .
Example 1:
Input :bookings = [[1,2,10],[2,3,20],[2,5,25]], n = 5
Output :[10,55,45,25,25]
explain :
Flight number 1 2 3 4 5
Booking records 1 : 10 10
Booking records 2 : 20 20
Booking records 3 : 25 25 25 25
Total number of seats : 10 55 45 25 25
therefore ,answer = [10,55,45,25,25]
Example 2:
Input :bookings = [[1,2,10],[2,2,15]], n = 2
Output :[10,25]
explain :
Flight number 1 2
Booking records 1 : 10 10
Booking records 2 : 15
Total number of seats : 10 25
therefore ,answer = [10,25]
Tips :
1 <= n <= 2 * 104
1 <= bookings.length <= 2 * 104
bookings[i].length == 3
1 <= firsti <= lasti <= n
1 <= seatsi <= 104
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/corporate-flight-bookings
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
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')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions _ Paper blog -CSDN Blog
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- Isam2 operation process
- [no app push general test plan
- E - 食物链
- [postman] test script writing and assertion details
- 黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
- Eigen稀疏矩阵操作
- 测试周期被压缩?教你9个方法去应对
- Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
- F - true liars (category and search set +dp)
- 2022 software testing workflow to know
猜你喜欢

Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai

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

keil MDK中删除添加到watch1中的变量

Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

Function of contenttype

Selenium source code read through · 9 | desiredcapabilities class analysis

F - true liars (category and search set +dp)

使用Nacos管理配置

Career advancement Guide: recommended books for people in big factories
随机推荐
技术分享 | 常见接口协议解析
这些年用Keil遇到的坑
Eigen稀疏矩阵操作
【Postman】Collections配置运行过程
「 WEB测试工程师 」岗位一面总结
模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
G - Supermarket
【eolink】PC客户端安装
MFC关于长字符串unsigned char与CString转换及显示问题
D - How Many Answers Are Wrong
进程和线程的理解
selenium源码通读·9 |DesiredCapabilities类分析
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
What are the test sites for tunnel engineering?
leaflet 地图
MySQL之基础知识
模拟卷Leetcode【普通】1447. 最简分数
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写