Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions leetcode3/남효정/636. Exclusive Time of Functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 풀이 실패
class Solution:
def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:
res = [0] * n
stack = []
prev_time = 0

for log in logs:
fn_id_str, typ, timestamp_str = log.split(":")
fn_id, curr_time = int(fn_id_str), int(timestamp_str)

if typ == "start":
# 이미 실행 중인게 있으면 실행시간 누적
# 이전 함수가 prev_time ~ curr_time - 1까지 수행되었음
if stack:
res[stack[-1]] += curr_time - prev_time

stack.append(fn_id)
prev_time = curr_time
else:
popped_id = stack.pop()
res[popped_id] += curr_time - prev_time + 1

# 타임스탬프 끝까지 차지하므로 다음 시작점은 +1임
prev_time = curr_time + 1

return res