Question 0 Daily Temperature母体
https://leetcode.com/problems/daily-temperatures/solutions/
Last updated
https://leetcode.com/problems/daily-temperatures/solutions/
Last updated
// Some code
class Solution {
public int[] dailyTemperatures(int[] temperatures) {
// sanity check
int[] result = new int[temperatures.length];
Deque<Integer> monoStack = new ArrayDeque<>();
for (int i = 0; i < temperatures.length; i++) {
int curTemp = temperatures[i];
while (!monoStack.isEmpty() && temperatures[monoStack.peekLast()] < curTemp) {
int index = monoStack.pollLast();
result[index] = i - index; // 谁置换你的,谁就是你的结果,被置换的人结果确定
}
monoStack.offerLast(i); //新来的一定要进栈,很容易忘(因为你需要看下能不能找到)
}
return result;
}
}