[LeetCode]636. Exclusive Time of Functions
来源:互联网 发布:线切割锥度怎样编程 编辑:程序博客网 时间:2024/06/05 16:14
https://leetcode.com/problems/exclusive-time-of-functions/#/description
给一个log数组,表示非抢占式CPU调用function的情况。格式为id:start or end:time
求每个func占用cpu的总时间
用stack保存当前还在调用栈内的func的id,pre记录前序时间。遇到start要push进入stack,遇到end要pop
public class Solution { public int[] exclusiveTime(int n, List<String> logs) { int[] res = new int[n]; Stack<Integer> stack = new Stack(); int pre = 0; for (String log : logs) { String[] arr = log.split(":"); if (arr[1].equals("start")) { if (!stack.isEmpty()) { res[stack.peek()] += Integer.parseInt(arr[2]) - pre; } stack.push(Integer.parseInt(arr[0])); pre = Integer.parseInt(arr[2]); } else { res[stack.pop()] += Integer.parseInt(arr[2]) - pre + 1; pre = Integer.parseInt(arr[2]) + 1; } } return res; }}
阅读全文
0 0
- [leetcode]636. Exclusive Time of Functions
- [LeetCode]636. Exclusive Time of Functions
- [LeetCode] 636. Exclusive Time of Functions
- leetcode 636. Exclusive Time of Functions
- 636. Exclusive Time of Functions
- 636. Exclusive Time of Functions
- LeetCode.636 Exclusive Time of Functions
- LeetCode636. Exclusive Time of Functions
- LeetCode 636 : Exclusive Time of Functions(python)
- leetcode 636. Exclusive Time of Functions 函数的单独运行时间
- Exclusive Time of Functions问题及解法
- Top 10 custom JavaScript functions of all time
- Windows MFC Time Functions
- Functions about time
- Some functions about time
- Compile-time Functions
- mysql 5.6 Date/Time Functions
- List of C functions
- Qt连接并操作SQL数据库(Qt学习①)
- opencv学习资源
- http(tcp/ip)
- jquery.easydropdown.min.js
- 将Java程序的输出结果写到txt文件中
- [LeetCode]636. Exclusive Time of Functions
- Servlet实现文件上传,可多文件上传
- twelve
- Vector类在中间插入字符串
- 详细解析Raid0、Raid0+1、Raid1、Raid5四者的区别
- 数组习题及详解
- [LeetCode] 31. Next Permutation
- Codeforces Round #425 (Div. 2)
- oracle解决因drop命令生成临时表名的问题(如表分区)