Monotonic Stack Data Structure All In One
单调堆栈
数据结构
errors
function dailyTemperatures(temperatures: number[]): number[] {
let answer = [];
for(let i = 0; i < temperatures.length; i++) {
let flag = false;
let days = 0;
let index = i;
while(index < temperatures.length) {
index += 1;
days += 1;
if(temperatures[index] > temperatures[i]) {
flag = true;
break;
}
}
if(!flag) {
answer[i] = 0;
} else {
answer[i] = days;
}
}
return answer;
};
/*
Time Limit Exceeded
47 / 48 testcases passed
temperatures =
[99,99, 99, ..., 99,99,100]
*/
solutions
demos
https://leetcode.com/problems/daily-temperatures/?envType=study-plan-v2&envId=leetcode-75
https://leetcode.com/problems/online-stock-span/description/?envType=study-plan-v2&envId=leetcode-75