当前位置:网站首页>2022.8.7-----leetcode.636
2022.8.7-----leetcode.636
2022-08-10 09:59:00 【路Lu727】
public int[] exclusiveTime(int n, List<String> logs) {
int[] ans=new int[n];
Deque<int[]> s=new ArrayDeque<>();//模拟当前调用
Deque<int[]> s1=new ArrayDeque<>();//存储已结束函数的起止点,包括同层函数与内部函数
for(String log:logs){
String[] ss=log.split(":");
if(ss[1].equals("start")){//调用起点入栈
s.add(new int[]{Integer.parseInt(ss[0]),Integer.parseInt(ss[2])});
}else{
int[] tmp=s.pollLast();
int time=Integer.parseInt(ss[2])-tmp[1]+1;//当前结束函数的调用间隔
while(!s1.isEmpty()&&s1.getLast()[0]>=tmp[1]){
int[] tmp1=s1.pollLast();
time-=tmp1[1]-tmp1[0]+1;//判断已结束函数是否位于当前结束函数内部
}
ans[tmp[0]]+=time;//累加时间
s1.add(new int[]{tmp[1],Integer.parseInt(ss[2])});//将当前结束函数加入栈
}
}
return ans;
}
边栏推荐
- 杭电多校七 1008-Triangle Game(博弈)
- 04 【计算属性 侦听器】
- Nvidia's gaming graphics card revenue plummets / Google data center explosion injures 3 people / iPhone battery percentage returns... More news today is here...
- keepalived:双主配置
- VBA: 遍历文件抓取指定条件的数据
- LCD DRM驱动框架分析二
- 裸辞→自我放松→闭关→复习→斩获Offer
- LiveGBS操作日志页面快速的筛选上级平台的调用记录直播观看录像回看等操作
- VBA: 采用Combox控件实现二级下拉菜单功能
- 【Software Exam System Architect】System Reliability Analysis and Design ① System Reliability Analysis
猜你喜欢
"Microservice Architecture" Arrangement and Choreography - Different Models for Making Systems Work Together
【企业架构】敏捷与企业架构:战略联盟
[System Design] S3 Object Storage
用高质量图像标注数据加速AI商业化落地
【元宇宙欧米说】看UCOUCO如何将行为艺术融入元宇宙
CentOS和Ubantu的Mysql主从配置
Tencent releases the second-generation version of the quadruped robot Max, which completes jumps and somersaults on the plum blossom pile
【物联网架构】什么是物联网平台?
DeepFake换脸诈骗怎么破?让他侧个身
「业务架构」TOGAF建模:组织分解图(组织映射)
随机推荐
CatchAdmin实战教程(四)Table组件之自定义基础页面
重学冒泡排序
多租户技术
IDEA中xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)
win下的开发环境变量记录
keepalived:双主配置
Shell脚本数组
Guo Jingjing's personal chess teaching, the good guy is a robot
「业务架构」TOGAF建模:业务功能分解图
【分布式】资源与事务:可观测性的基本二重性
如何理解BIO、NIO、AIO的区别
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
09 【Attributes继承 provide与inject】
Chapter 3 Search and Graph Theory (3)
【数据库架构】OLTP 和 OLAP:实际比较
「业务架构」TAGAF建模:业务服务/信息图
[Data Architecture] Distributed Data Grid as a Solution for Centralized Data Monolith
"Guangzhou highway engineering measures for the supervision and administration of production safety, and revised from six aspects
90.(cesium之家)cesium高度监听事件
JWT: To own me is to have power