Skip to content

Commit c62d5cf

Browse files
authored
Create 636. Exclusive Time of Functions.py
1 parent f43c0a1 commit c62d5cf

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:
3+
stack = []
4+
ans = [0] * n
5+
6+
prev_time = 0
7+
8+
for log in logs:
9+
id, se, time = log.split(":")
10+
id = int(id)
11+
time = int(time)
12+
13+
if se == "start":
14+
if stack:
15+
ans[stack[-1]] += time - prev_time
16+
17+
stack.append(id)
18+
prev_time = time
19+
20+
else: # end
21+
ans[stack[-1]] += time - prev_time + 1
22+
stack.pop()
23+
prev_time = time + 1
24+
25+
return ans

0 commit comments

Comments
 (0)