当前位置:网站首页>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 !
边栏推荐
- 10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
- JMeter做接口测试,如何提取登录Cookie
- Fault, error, failure of functional safety
- 黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
- 【Postman】Monitors 监测API可定时周期运行
- win10无法操作(删除、剪切)文件
- Sqlmap tutorial (III) practical skills II
- Function of activation function
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- [ram IP] introduction and experiment of ram IP core
猜你喜欢
JWT-JSON WEB TOKEN
职场进阶指南:大厂人必看书籍推荐
调用链监控Zipkin、sleuth搭建与整合
Selenium source code read through · 9 | desiredcapabilities class analysis
[eolink] PC client installation
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
【Postman】Collections配置运行过程
异常检测方法总结
Career advancement Guide: recommended books for people in big factories
随机推荐
Web界面元素的测试
PAT(乙级)2022年夏季考试
(中)苹果有开源,但又怎样呢?
[eolink] PC client installation
【微信小程序】搭建开发工具环境
模拟卷Leetcode【普通】1447. 最简分数
[C language] qsort function
模拟卷Leetcode【普通】1219. 黄金矿工
Pat (Grade B) 2022 summer exam
Significance of unit testing
【C语言】字符串左旋
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Construction and integration of Zipkin and sleuth for call chain monitoring
黑猫带你学UFS协议第4篇:UFS协议栈详解
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Full link voltage measurement: building three models
【Postman】Monitors 监测API可定时周期运行
Leaflet map
[leetcode] day96 - the first unique character & ransom letter & letter ectopic word
JWT-JSON WEB TOKEN