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)


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