From d0f78c9b7ae615d9af9fc80b8eb05d351a174acb Mon Sep 17 00:00:00 2001 From: Rui Yang <35053274+littlecry@users.noreply.github.com> Date: Tue, 10 Nov 2020 22:57:11 -0600 Subject: [PATCH] =?UTF-8?q?Update=20=E5=8D=95=E8=B0=83=E6=A0=88.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add Java solution for Leetcode 739. Daily Temperatures --- 数据结构系列/单调栈.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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; + } +}