class Solution { public: vector dailyTemperatures(vector& T) { stack stk; vector res(T.size(), 0); int i = 0; while (i < T.size()) { if (stk.empty() || T[stk.top()] >= T[i]) { stk.push(i); i++; } else { int top = stk.top(); stk.pop(); res[top] = i - top; } } return res; } };