Python, stack with time taken


  • 0
    B
    def exclusiveTime(self, n, logs):
        ret=[0]*n
        st=[]
        
        for log_val in logs:
            lid,se,time_val=log_val.split(':')
            lid=int(lid);time_val=int(time_val)
    
            if se=='start':
                st.append([time_val,0]) # start time, taken time by other. 
            else: # 'end'
                stime,taken=st.pop()
                ret[lid]+=time_val-stime+1-taken
                if st: st[-1][1]+=time_val-stime+1
        return ret

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.