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