当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
90.(cesium之家)cesium高度监听事件
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
【物联网架构】什么是物联网平台?
腾讯发布四足机器人 Max 二代版本,梅花桩上完成跳跃、空翻
12 【其它组合式API】
07 【动态组件 组件注册】
[Internet of Things Architecture] The most suitable open source database for the Internet of Things
「技术选型」工作流引擎哪家强?首席架构帮你挑
【数据架构】概念数据模型和逻辑数据模型有什么区别
随机推荐
单例模式基类
【物联网架构】什么是物联网平台?
07 【动态组件 组件注册】
《广州市公路工程安全生产监督管理办法》印发,从六大方面进行修订
在“企业通讯录”的盲区,融云的边界与分寸
【数据仓库】什么是 Azure Synapse,它与 Azure Data Bricks 有何不同?
"Data Architecture": How can master data management (MDM) help my industry?
[Internet of Things Architecture] The most suitable open source database for the Internet of Things
LiveNVR操作日志页面快速筛选上级国标平台的调用记录直播观看录像回看等操作
【API 管理】什么是 API 管理,为什么它很重要?
VBA: 遍历文件抓取指定条件的数据
亚信AntDB数据库有啥业务应用场景和应用案例?
[Metaverse Omi Says] Listen to how Rabbit Fan Rabbit creates a new era of trendy play from virtual to reality
Shell脚本数组
makefile 杂项
12 【其它组合式API】
【Enterprise Architecture】Agile and Enterprise Architecture: Strategic Alliance
用.bat文件做Airtest脚本的多设备批量运行
Static关键字及应用,继承的概念
【Software Exam System Architect】System Reliability Analysis and Design ① System Reliability Analysis