leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0739.cpp (474B)


0 class Solution { 1 public: 2 vector<int> dailyTemperatures(vector<int> &temps) { 3 stack<int> st({0}); 4 5 for (int i = 1; i < temps.size(); ++i) { 6 while (!st.empty() && temps[i] > temps[st.top()]) { 7 temps[st.top()] = i - st.top(); 8 st.pop(); 9 } 10 st.push(i); 11 } 12 13 while (!st.empty()) { 14 temps[st.top()] = 0; 15 st.pop(); 16 } 17 return temps; 18 } 19 };