// TODO: need improve!!!
class Log {
public:
int id;
bool start;
int timestamp;
int comp; // compasation
Log() {
id = ;
timestamp = ;
comp = ;
start = false;
}
};
class Solution {
public:
vector<int> exclusiveTime(int n, vector<string>& logs) {
vector<int> res(n, );
stack<Log> s;
for (auto &log : logs) {
auto item = parseLog(log);
if (item.start)
s.push(item);
else {
int comp = item.timestamp - s.top().timestamp + ;
int exTime = item.timestamp - s.top().timestamp + - s.top().comp;
res[item.id] += exTime;
s.pop();
if (!s.empty()) {
s.top().comp += comp;
}
}
}
return res;
}
Log parseLog(const string& s) {
int col1 = s.find(":");
int col2 = s.find(":", col1 + );
int id = stoi(s.substr(, col1));
int time = stoi(s.substr(col2 + ));
string state = s.substr(col1 + , col2 - col1 - ); Log log;
if (state == "start")
log.start = true;
log.id = id;
log.timestamp = time; return log;
}
};

636. Exclusive Time of Functions的更多相关文章

  1. [leetcode]636. Exclusive Time of Functions函数独占时间

    Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...

  2. 636. Exclusive Time of Functions 进程的执行时间

    [抄题]: Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU ...

  3. [LeetCode] 636. Exclusive Time of Functions 函数的独家时间

    Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...

  4. 【LeetCode】636. Exclusive Time of Functions 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode ...

  5. 【leetcode】636. Exclusive Time of Functions

    题目如下: 解题思路:本题和括号匹配问题有点像,用栈比较适合.一个元素入栈前,如果自己的状态是“start”,则直接入栈:如果是end则判断和栈顶的元素是否id相同并且状态是“start”,如果满足这 ...

  6. Leetcode 之 Exclusive Time of Functions

    636. Exclusive Time of Functions 1.Problem Given the running logs of n functions that are executed i ...

  7. [LeetCode] Exclusive Time of Functions 函数的独家时间

    Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...

  8. [Swift]LeetCode636. 函数的独占时间 | Exclusive Time of Functions

    Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...

  9. Exclusive Time of Functions

    On a single threaded CPU, we execute some functions.  Each function has a unique id between 0 and N- ...

随机推荐

  1. hibernate课程 初探一对多映射2-6 测试-添加和查询学生信息

    package com.ddwei.entity; import java.util.Set; import org.hibernate.Session; import org.hibernate.T ...

  2. python面试题——爬虫相关

    1.接触过几种爬虫模块 urllib.requests这两种爬虫模块. 2.robots协议是什么? 它就是一个防君子不防小人的协议,网站有一些数据不想被爬虫程序爬取,可以编写robots协议文件,明 ...

  3. 洛谷P3128 [USACO15DEC]最大流Max Flow(树上差分)

    题意 题目链接 Sol 树上差分模板题 发现自己傻傻的分不清边差分和点差分 边差分就是对边进行操作,我们在\(u, v\)除加上\(val\),同时在\(lca\)处减去\(2 * val\) 点差分 ...

  4. viewport信息设置

  5. sqlalchemy的cascades

    http://docs.sqlalchemy.org/en/latest/orm/cascades.html class Order(Base): __tablename__ = 'order' it ...

  6. Angular2、4入门基础知识(小的概念)

    1. 使用引用符来格式化HTML代码. @Component({ selector: 'app-heroes', templateUrl: './heroes.component.html', sty ...

  7. MyEclipse 相关配置操作、问题处理及快捷键说明

    MyEclipse傻瓜式安装不做介绍,试用期结束后破解操作见博客:MyEclipse 2014 破解补丁及激活步骤 以下为安装完MyEclipse后一般需要进行的一些配置,写来自己参考用.比较简陋,望 ...

  8. SIP MGCP和H323的区别

    在Windows中内置的NetMeeting就是典型的H.323协议客户端,而比较常见的SIP系统是微软开发的MSN Messenger系统.首先,由用户A向SIP服务器发出呼叫请求,请求的信息包含自 ...

  9. 【BZOJ1269】[AHOI2006] 文本编辑器editor(Splay)

    点此看题面 大致题意: 让你维护一个字符串,有插入字符串.删除区间.反转区间和输出单个字符操作. \(Splay\) 这应该是一道比较简单的\(Splay\)题(虽然因为各种细节我调了很久). 我们可 ...

  10. leetCode没那么难啦 in Java (一)

    前言    感觉写博客是一个很耗心力的东西T_T,简单的写了似乎没什么用,复杂的三言两语也只能讲个大概,呸呸...怎么能有这些消极思想呢QAQ!那想来想去,先开一个leetcode的坑,虽然已经工作了 ...