当前位置:网站首页>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 !
边栏推荐
- Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
- MySQL之数据类型
- keil MDK中删除添加到watch1中的变量
- 對數據安全的思考(轉載)
- Selenium source code read through · 9 | desiredcapabilities class analysis
- Nodejs realizes the third-party login of Weibo
- 模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
- 10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
- CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
- [C language] string left rotation
猜你喜欢
Customize the gateway filter factory on the specified route
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
[API interface tool] Introduction to postman interface
[postman] test script writing and assertion details
Hypothesis testing learning notes
keil MDK中删除添加到watch1中的变量
Basic knowledge of error
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
[postman] collections configuration running process
浅谈专项测试之弱网络测试
随机推荐
Win10 cannot operate (delete, cut) files
Manage configuration using Nacos
On weak network test of special test
浅谈专项测试之弱网络测试
Function of contenttype
数据库隔离级别
[postman] the monitors monitoring API can run periodically
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Application of Lie group in gtsam
Significance of unit testing
Linux regularly backs up MySQL database
sourceInsight中文乱码
Understanding of processes and threads
在线问题与离线问题
Aike AI frontier promotion (2.13)
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
P问题、NP问题、NPC问题、NP-hard问题详解
Resttemplate and feign realize token transmission
调用链监控Zipkin、sleuth搭建与整合
数字三角形模型 AcWing 1015. 摘花生