class Solution {
public int[] dailyTemperatures(int[] temperatures) {
int[] ans = new int[temperatures.length];
Stack<Integer> stack = new Stack<>();
for (int currDay = 0; currDay < temperatures.length; currDay++) {
while (
!stack.isEmpty() &&
temperatures[currDay] > temperatures[stack.peek()]
) {
int prevDay = stack.pop();
ans[prevDay] = currDay - prevDay;
}
stack.add(currDay);
}
return ans;
}
}