From 9bcfa00a1c28792d7a0d6e19288aab0cdadfc83e Mon Sep 17 00:00:00 2001 From: masterMJ Date: Sat, 29 Aug 2026 21:21:26 +0900 Subject: [PATCH] Create 636_Exclusive_Time_of_Functions.py --- .../636_Exclusive_Time_of_Functions.py" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "leetcode3/\352\271\200\353\257\274\354\240\234/636_Exclusive_Time_of_Functions.py" diff --git "a/leetcode3/\352\271\200\353\257\274\354\240\234/636_Exclusive_Time_of_Functions.py" "b/leetcode3/\352\271\200\353\257\274\354\240\234/636_Exclusive_Time_of_Functions.py" new file mode 100644 index 00000000..307e0d0f --- /dev/null +++ "b/leetcode3/\352\271\200\353\257\274\354\240\234/636_Exclusive_Time_of_Functions.py" @@ -0,0 +1,34 @@ +from typing import List + +''' +문제 풀이 이해는 했지만 +직접 풀지는 못했음. +''' + +class Solution: + def exclusiveTime(self, n: int, logs: List[str]) -> List[int]: + stack = [] + result = [0] * n + prev_time = 0 + + for log in logs: + temp = log.split(":") + func_id = int(temp[0]) + action = temp[1] + timestamp = int(temp[2]) + + if action =="start": + if stack: + result[stack[-1]] += timestamp-prev_time + stack.append(func_id) + prev_time = timestamp + else: + result[stack.pop()] += timestamp - prev_time +1 + prev_time = timestamp+1 + return result + +n = 2 +logs = ["0:start:0","1:start:2","1:end:5","0:end:6"] + +solution = Solution() +print(solution.exclusiveTime(n,logs))