please help me with my code,why runtime error?


  • 0
    H

    struct Node
    {
    int num;
    bool flag;
    int time;
    };

    class Solution {
    public:
    vector<int> exclusiveTime(int n, vector<string>& logs) {
    int kk;
    stack<int> sk;
    vector<int> ans(n);
    for(int i=0;i<n;i++)
    {
    ans[i]=0;
    }
    vector<Node> v;
    for(int i=0;i<logs.size();i++)
    {
    char c;
    int num;
    string s;
    stringstream ss(logs[i]);
    ss>>num>>c>>s;
    Node node;
    node.num=num;
    if(s[0]=='s')
    {
    s=s.substr(6);
    node.flag=0;
    node.time=stoi(s);
    }
    else
    {
    s=s.substr(4);
    node.flag=1;
    node.time=stoi(s);
    }
    cout<<node.num<<"!"<<node.flag<<"!"<<node.time<<endl;
    v.push_back(node);
    if(v[i].flag==0)
    {
    sk.push(v[i].time);
    }
    else
    {
    ans[v[i].num]+=(v[i].time-sk.top()+1);
    kk=v[i].time-sk.top()+1;
    sk.pop();
    if(!sk.empty())
    {
    ans[sk.top()]-=kk;
    }
    }
    }
    cout<<"$$$"<<endl;
    return ans;
    }
    };
    my code can even cout "$$$",i cannot find the bug


Log in to reply
 

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