From 2337257dd505dda7b6a48a5c1ff44c87c28bd2d7 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Sat, 29 Aug 2026 23:43:38 +0900 Subject: [PATCH 1/2] 636. Exclusive Time of Functions --- .../636. Exclusive Time of Functions.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" new file mode 100644 index 000000000..e69de29bb From d590106a8485b96725914dca259ddaa5dbbc9810 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Sat, 29 Aug 2026 23:43:52 +0900 Subject: [PATCH 2/2] 636. Exclusive Time of Functions --- .../636. Exclusive Time of Functions.java" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" index e69de29bb..3a80a5eba 100644 --- "a/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/636. Exclusive Time of Functions.java" @@ -0,0 +1,31 @@ +class Solution { + public int[] exclusiveTime(int n, List logs) { + int[] answer = new int[n]; + Deque stack = new ArrayDeque<>(); + + int prevTime = 0; + + for (String log : logs) { + String[] parts = log.split(":"); + + int id = Integer.parseInt(parts[0]); + String type = parts[1]; + int time = Integer.parseInt(parts[2]); + + if (type.equals("start")) { + if (!stack.isEmpty()) { + answer[stack.peek()] += time - prevTime; + } + + stack.push(id); + prevTime = time; + + } else { + answer[stack.pop()] += time - prevTime + 1; + prevTime = time + 1; + } + } + + return answer; + } +} \ No newline at end of file