C++ solution with Stack


  • 0
    R
    vector<int> dailyTemperatures(vector<int>& temperatures) {
            vector<int> v(temperatures.size(),0);
            stack<pair<int,int>> s;
            for(int i=0;i<temperatures.size();i++)
            {
                while((s.empty()==false)&&((s.top()).first<temperatures[i]))
                {
                    v[(s.top()).second] = (i-(s.top()).second);
                    s.pop();
                }
                s.push(make_pair(temperatures[i],i));
            }
            return v;
        }
    

Log in to reply
 

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