diff --git a/daily-temperatures/daily-temperatures.cpp b/daily-temperatures/daily-temperatures.cpp new file mode 100644 index 0000000..7007da6 --- /dev/null +++ b/daily-temperatures/daily-temperatures.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + vector dailyTemperatures(vector& temperatures) { + stack> stk; + int n = temperatures.size(); + vector waitDays(n, 0); + for(int i = n-1; i >= 0; i--) { + if(stk.empty()) + stk.push({temperatures[i], i}); + else { + while(!stk.empty() && stk.top().first <= temperatures[i]) + stk.pop(); + if(!stk.empty()) + waitDays[i] = stk.top().second - i; + stk.push({temperatures[i], i}); + } + } + return waitDays; + } +}; \ No newline at end of file