Update 单调栈.md

add Java solution for Leetcode 739. Daily Temperatures
This commit is contained in:
Rui Yang
2020-11-10 22:57:11 -06:00
committed by GitHub
parent 8b8f413585
commit d0f78c9b7a

View File

@ -181,4 +181,19 @@ vector<int> nextGreaterElements(vector<int>& nums) {
<img src="../pictures/qrcode.jpg" width=200 >
</p>
======其他语言代码======
======其他语言代码======
// 739. Daily Temperatures
class Solution {
public int[] dailyTemperatures(int[] T) {
Stack<Integer> stack = new Stack<>();
int[] ans = new int[T.length];
for (int i = 0; i < T.length; i++) {
while (!stack.isEmpty() && T[i] > T[stack.peek()]) {
int index = stack.pop();
ans[index] = i - index;
}
stack.push(i);
}
return ans;
}
}