Skip to content

Commit 42309aa

Browse files
Merge pull request #1931 from CodingTestStudy2/최민지
[최민지] Day31
2 parents 0586525 + f400d36 commit 42309aa

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎leetcode3/최민지/636.py‎

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

0 commit comments

Comments
 (0)