Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef int* Stack; // just a fancier name for an array
- class Solution {
- public:
- vector<int> dailyTemperatures(vector<int>& temperatures) {
- const int N = temperatures.size();
- vector<int> sol(N,0);
- Stack stack_top = (Stack) alloca(sizeof(int) * (N-1));
- Stack stack_base = stack_top;
- for(long i = 0; i < N - 1;++i)
- {
- if(temperatures[i] < temperatures[i+1])
- {
- sol[i] = 1;
- while(stack_base != stack_top && temperatures[*(stack_top-1)] < temperatures[i+1])
- {
- sol[*(stack_top -1 )] = i + 1 - *(stack_top - 1);
- if( stack_base != stack_top) --stack_top;
- }
- }
- else
- {
- *stack_top++ = i;
- }
- }
- return sol;
- }
- };
Add Comment
Please, Sign In to add comment