daily-temperatures 1.0.0
Daily Temperatures
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <bits/stdc++.h>
2
3using namespace std;
4
6{
7public:
8 vector<int> dailyTemperatures(vector<int>& temperatures)
9 {
10 stack<int> temp_ind; // temperature indices - monotonic stack
11 int size = (int)temperatures.size();
12 vector<int> days(size, 0);
13 for (int i = 0; i < size; ++i)
14 {
15 while (!temp_ind.empty() && temperatures[i] > temperatures[temp_ind.top()])
16 {
17 days[temp_ind.top()] = i - temp_ind.top();
18 temp_ind.pop();
19 }
20 temp_ind.push(i);
21 }
22 return days;
23 }
24};
25
26int main()
27{
28
29 return 0;
30}
vector< int > dailyTemperatures(vector< int > &temperatures)
Definition main.cpp:8
int main()
Definition main.cpp:26