//栈中存储数组下标,从后往前遍历比较,可以省去从前往后的数组过大的麻烦
public static int[] dailyTemperatures(int[] temperatures) {
int[] ans = new int[temperatures.length];Stack<Integer> stack = new Stack();
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;
}