# leetcode刷题（85）——739.每日温度

1.暴力法

public int[] dailyTemperatures(int[] T) {
int[] res = new int[T.length];
for (int i = 0; i < T.length - 1; i++) {
for (int j = i + 1; j < T.length - 1; j++) {
if (T[j] > T[i]) {
res[i] = j-i;
break;
}
}
}
return res;
}


2.单调栈

stack=[0(73)]

ans=[0,0,0,0,0,0,0,0]

stack=[1(74)]

ans=[1,0,0,0,0,0,0,0]

stack=[2(75)]

ans=[1,1,0,0,0,0,0,0]

stack=[2(75),3(71)]

ans=[1,1,0,0,0,0,0,0]

stack=[2(75),3(71),4(69)]

ans=[1,1,0,0,0,0,0,0]

stack=[2(75),5(72)]

ans=[1,1,0,2,1,0,0,0]

stack=[6(76)]

ans=[1,1,4,2,1,1,0,0]

stack=[6(76),7(73)]

ans=[1,1,4,2,1,1,0,0]

 public int[] dailyTemperatures2(int[] T) {
int length = T.length;
int[] ans = new int[length];
Deque<Integer> stack = new LinkedList<Integer>();
for (int i = 0; i < length; i++) {
int temperature = T[i];
while (!stack.isEmpty() && temperature > T[stack.peek()]) {
int prevIndex = stack.pop();
ans[prevIndex] = i - prevIndex;
}
stack.push(i);
}
return ans;
}


06-11 53

06-28 1351

04-19 150

04-02 444

06-11 85

06-11 62

04-04 117

06-11 60

06-11 96

07-30 35

#### Leetcode第739题--每日温度

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。