mirror of
https://github.com/labuladong/fucking-algorithm.git
synced 2025-07-05 12:04:37 +08:00
Update 单调栈.md
add Java solution for Leetcode 739. Daily Temperatures
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user