当前位置:网站首页>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 !
边栏推荐
- 【Postman】动态变量(也称Mock函数)
- Summary of anomaly detection methods
- 【微信小程序】搭建开发工具环境
- Request forwarding and redirection
- GTSAM中ISAM2和IncrementalFixedLagSmoother说明
- MySQL之基础知识
- F - true liars (category and search set +dp)
- Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
- [C language] qsort function
- (中)苹果有开源,但又怎样呢?
猜你喜欢
JWT-JSON WEB TOKEN
selenium源码通读·9 |DesiredCapabilities类分析
JMeter做接口测试,如何提取登录Cookie
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
Sqlmap tutorial (III) practical skills II
【微信小程序】搭建开发工具环境
Seven imperceptible truths in software testing
Understanding of processes and threads
异常检测方法总结
[web security] nodejs prototype chain pollution analysis
随机推荐
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
MFC关于长字符串unsigned char与CString转换及显示问题
JWT-JSON WEB TOKEN
通过修改style设置打印页样式
Commodity price visualization
[no app push general test plan
B - The Suspects
【Postman】Monitors 监测API可定时周期运行
Luogu p1460 [usaco2.1] healthy Holstein cows
Selenium source code read through · 9 | desiredcapabilities class analysis
[postman] collections configuration running process
P问题、NP问题、NPC问题、NP-hard问题详解
LeetCode 732. 我的日程安排表 III
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
Digital triangle model acwing 1015 Picking flowers
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
异常检测方法总结
Interface test: what are the components of the URL in fiddler
在线问题与离线问题