class Solution {
public int[] dailyTemperatures(int[] temperatures) {
Deque<Integer> stack = new ArrayDeque<>();
int n = temperatures.length;
int[] ans = new int[n]; // 默认全是 0
for (int i = 0; i < n; i++) {
while (!stack.isEmpty() && temperatures[stack.peekLast()] < temperatures[i]) {
int idx = stack.pollLast();
ans[idx] = i - idx;
}
stack.offerLast(i);
}
return ans;
}
}