739.Daily Temperatures
https://leetcode.com/problems/daily-temperatures/solution/[
](https://leetcode.com/problems/daily-temperatures/description/)1-Using Stack
class Solution {
public int[] dailyTemperatures(int[] temperatures) {
int[] ans = new int[temperatures.length];
Deque<Integer> stack = new ArrayDeque<>();
for(int i = temperatures.length - 1; i >= 0; i--){
while(!stack.isEmpty() && temperatures[i] >= temperatures[stack.peek()]){
stack.pop();
}
ans[i] = stack.isEmpty() ? 0 : stack.peek() - i;
stack.push(i);
}
return ans;
}
}