Good idea to make it concise. Implement your idea in C++

class Solution { public: vector<int> exclusiveTime(int n, vector<string>& logs) { vector<int> result(n, 0); stack<int> sk; int prev_time = 0; for(const string& log:logs) { bool start = true; int id = 0, time = 0; decompose(log, start, id, time); if(!sk.empty()) result[sk.top()] += time-prev_time; prev_time = time; if(start) { sk.push(id); } else { result[sk.top()]++; prev_time++; sk.pop(); } } return result; } private: void decompose(const string& log, bool& start, int& id, int& time) { int i = 0; while(log[i]!=':') i++; id = stoi(log.substr(0,i)); start = true; if(log[++i]=='e') start=false; if(start) time = stoi(log.substr(i+6, log.length()-i-6)); else time = stoi(log.substr(i+4, log.length()-i-4)); } };Exclusive Time of Functions