递减栈 Descending Stack, Time = O(n), Space = O(n)
class Solution {
public int[] dailyTemperatures(int[] T) {
int[] wait = new int[T.length];
Deque<Integer> stack = new ArrayDeque<>();
for (int day = 0; day < T.length; day++) {
while (! stack.isEmpty() && T[day] > T[stack.peekFirst()]) {
int previousDay = stack.pollFirst();
wait[previousDay] = day - previousDay;
}
stack.offerFirst(day);
}
return wait;
}
}