赞
踩
解题思路:
- class Solution {
- public int[] dailyTemperatures(int[] temperatures) {
- int length = temperatures.length;
- int[] ans = new int[length];
- Deque<Integer> stack = new LinkedList<>();
- for (int i = 0; i < length; i++) {
- int temperature = temperatures[i];
- while (!stack.isEmpty() && temperature > temperatures[stack.peek()]) {
- int preIndex = stack.pop();
- ans[preIndex] = i - preIndex;
- }
- stack.push(i);
- }
- return ans;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。