Skip to content

Commit 441d87a

Browse files
Merge pull request #1935 from CodingTestStudy2/남효정
[남효정] Day31
2 parents f22a95a + 338a492 commit 441d87a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 풀이 실패
2+
class Solution:
3+
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:
4+
res = [0] * n
5+
stack = []
6+
prev_time = 0
7+
8+
for log in logs:
9+
fn_id_str, typ, timestamp_str = log.split(":")
10+
fn_id, curr_time = int(fn_id_str), int(timestamp_str)
11+
12+
if typ == "start":
13+
# 이미 실행 중인게 있으면 실행시간 누적
14+
# 이전 함수가 prev_time ~ curr_time - 1까지 수행되었음
15+
if stack:
16+
res[stack[-1]] += curr_time - prev_time
17+
18+
stack.append(fn_id)
19+
prev_time = curr_time
20+
else:
21+
popped_id = stack.pop()
22+
res[popped_id] += curr_time - prev_time + 1
23+
24+
# 타임스탬프 끝까지 차지하므로 다음 시작점은 +1임
25+
prev_time = curr_time + 1
26+
27+
return res

0 commit comments

Comments
 (0)