这里有 n 个航班,它们分别从 1 到 n 进行编号。

有一份航班预订表 bookings ,表中第 i 条预订记录 bookings[i] = [firsti, lasti, seatsi] 意味着在从 firsti 到 lasti (包含 firsti 和 lasti )的 每个航班 上预订了 seatsi 个座位。

请你返回一个长度为 n 的数组 answer,里面的元素是每个航班预定的座位总数。

 

示例 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]

class Solution:
def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
#创建一个和n长度一致的列表
base=[0 for i in range(n)]
for first , last , seat in bookings:
#只把所有first的加上,last的值减去
base[first-1] += seat
if last < n:
base[last] -=seat
#然后把前缀相加求和
temp=0
result=[]
for i in range(n):
temp +=base[i]
result.append(temp)
return result

最新文章

  1. JSONArray的应用
  2. 搭建centos测试环境:window安装xshell,WinSCP 。 centos安装jdk tomcat
  3. 推流和拉流的概念以及RTMP和HLS协议
  4. activeMQ 安装于使用
  5. Python笔记-built-in函数,文件操作,lambda函数
  6. 【转】Ant学习笔记——自己构建Ant编译环境
  7. SQLSERVER 2012之AlwaysOn -- 同步模式下的网卡性能优化
  8. 【原】对频率论(Frequentist)方法和贝叶斯方法(Bayesian Methods)的一个总结
  9. 20150914 异常语句 math的方法 去空格 索引
  10. 在eclipse中运行storm-starter
  11. ASP.net+MVC--2
  12. A. Initial Bet(Codeforces Round #273)
  13. JavaScript(五):函数(闭包,eval)
  14. Android进阶(十六)子线程调用Toast报Can&#39;t create handler inside thread that has not called Looper.prepare() 错误
  15. Snapde电子表格支持的文件格式
  16. 【RL-TCPnet网络教程】第2章 嵌入式网络协议栈基础知识
  17. ORA-12557协议适配器不可加载
  18. spring cloud (二、服务注册安全demo_eureka)
  19. 类 __new__方法实现单例
  20. (转)干货|这篇TensorFlow实例教程文章告诉你GANs为何引爆机器学习?(附源码)

热门文章

  1. Java访问修饰符和三大特征(封装,继承和多态)
  2. like使用索引如何避免失效
  3. 基于zynq XC7Z100 FMC接口通用计算平台
  4. Dubbo SPI机制之三Adaptive自适应功能
  5. Spring容器变化之SmartLifecycle,LifecycleProcesso接口详述
  6. C语言中左值和右值的理解
  7. 能无缝嵌入Excel的报表工具,报表轻松做!
  8. 【硬件基础知识】指令集框架(ISA:Instruction Set Architecture)
  9. 『无为则无心』Python日志 — 64、Python日志模块logging介绍
  10. linux 测试机器端口连通性方法