Skip to content

Commit 9bcfa00

Browse files
authored
Create 636_Exclusive_Time_of_Functions.py
1 parent 2934962 commit 9bcfa00

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import List
2+
3+
'''
4+
문제 풀이 이해는 했지만
5+
직접 풀지는 못했음.
6+
'''
7+
8+
class Solution:
9+
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:
10+
stack = []
11+
result = [0] * n
12+
prev_time = 0
13+
14+
for log in logs:
15+
temp = log.split(":")
16+
func_id = int(temp[0])
17+
action = temp[1]
18+
timestamp = int(temp[2])
19+
20+
if action =="start":
21+
if stack:
22+
result[stack[-1]] += timestamp-prev_time
23+
stack.append(func_id)
24+
prev_time = timestamp
25+
else:
26+
result[stack.pop()] += timestamp - prev_time +1
27+
prev_time = timestamp+1
28+
return result
29+
30+
n = 2
31+
logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]
32+
33+
solution = Solution()
34+
print(solution.exclusiveTime(n,logs))

0 commit comments

Comments
 (0)