Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int[] exclusiveTime(int n, List<String> logs) {
- int[] res = new int[n];
- Stack<int[]> stack = new Stack<>();
- for (String tag: logs) {
- String[] tokens = tag.split(":");
- Integer p = Integer.parseInt(tokens[0]), t = Integer.parseInt(tokens[2]);
- if (tokens[1].equals("start")) {
- stack.push(new int[]{p, t});
- } else {
- int[] last = stack.pop();
- int dur = t - last[1] + 1;
- res[p] += dur;
- if (!stack.isEmpty())
- res[stack.peek()[0]] -= dur;
- }
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement