当前位置:网站首页>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;
}
边栏推荐
- "Guangzhou highway engineering measures for the supervision and administration of production safety, and revised from six aspects
- 数据库中的schema
- Which is the strongest workflow engine for "Technology Selection"?Chief Architecture Helps You Pick
- [Internet of Things Architecture] The most suitable open source database for the Internet of Things
- 傅立叶级数与傅里叶变换
- The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
- 「业务架构」TOGAF建模:组织分解图(组织映射)
- 多元线性回归分析(Stata)
- 裸辞→自我放松→闭关→复习→斩获Offer
- 08 【Props 组件事件】
猜你喜欢
08 【Props 组件事件】
[System Design] S3 Object Storage
90.(cesium之家)cesium高度监听事件
JS高级 之 Promise 详解
在兄弟连战狼班参加PHP培训做行业领先人才
「业务架构」TOGAF建模:组织分解图(组织映射)
How to break the DeepFake face-changing scam?turn him over
裸辞→自我放松→闭关→复习→斩获Offer
Payment x Aggregation x Ledger Separation - The Way to Avoid Risk of "Erqing" on the Return Platform
Numpy学习
随机推荐
「技术选型」工作流引擎哪家强?首席架构帮你挑
细说Redis监控和告警
jq封装树形下拉选择框组件
绘制温度曲线图;QChart,
【软考 系统架构设计师】案例分析⑥ Web应用系统架构设计
用高质量图像标注数据加速AI商业化落地
【数据仓库】什么是 Azure Synapse,它与 Azure Data Bricks 有何不同?
【Software Exam System Architect】System Reliability Analysis and Design ① System Reliability Analysis
在兄弟连战狼班参加PHP培训做行业领先人才
web项目访问引用jar内部的静态资源
「数据战略」结果驱动的企业数据策略:组织和治理
The web project accesses static resources inside the reference jar
序列化技术ProtoBuf
武功修炼:内功
keepalived:主备配置
JS高级 之 Promise 详解
[Internet of Things Architecture] The most suitable open source database for the Internet of Things
win下的开发环境变量记录
makefile 杂项
支付 x 聚合 x 分账 - 回流平台“二清”风险规避之路