-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexclusiveTime.py
More file actions
27 lines (19 loc) · 811 Bytes
/
exclusiveTime.py
File metadata and controls
27 lines (19 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:
stack=[]
ret=[0]*n
for element in logs:
element= element.split(':')
print(stack)
if stack:
if element[1]=="start":
ret[int(stack[-1][0])]+=int(element[2])-int(prev)
else:
ret[int(stack[-1][0])]+=int(element[2])-int(prev)+1
if element[1]=="start":
# if stack and element[0]!=stack[-1][0]:
stack.append([element[0], element[2]])
else:
stack.pop()
prev=element[2]
return ret