From c62d5cf8aaf465141fed1031b64141981a6eaa1e Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sat, 29 Aug 2026 21:01:40 +0900 Subject: [PATCH] Create 636. Exclusive Time of Functions.py --- .../636. Exclusive Time of Functions.py" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/636. Exclusive Time of Functions.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/636. Exclusive Time of Functions.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/636. Exclusive Time of Functions.py" new file mode 100644 index 00000000..23955887 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/636. Exclusive Time of Functions.py" @@ -0,0 +1,25 @@ +class Solution: + def exclusiveTime(self, n: int, logs: List[str]) -> List[int]: + stack = [] + ans = [0] * n + + prev_time = 0 + + for log in logs: + id, se, time = log.split(":") + id = int(id) + time = int(time) + + if se == "start": + if stack: + ans[stack[-1]] += time - prev_time + + stack.append(id) + prev_time = time + + else: # end + ans[stack[-1]] += time - prev_time + 1 + stack.pop() + prev_time = time + 1 + + return ans