diff --git a/数据结构系列/单调栈.md b/数据结构系列/单调栈.md index fca0ca8..7853fc1 100644 --- a/数据结构系列/单调栈.md +++ b/数据结构系列/单调栈.md @@ -181,4 +181,19 @@ vector nextGreaterElements(vector& nums) {

-======其他语言代码====== \ No newline at end of file +======其他语言代码====== +// 739. Daily Temperatures +class Solution { + public int[] dailyTemperatures(int[] T) { + Stack 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; + } +}