class Solution {
public int[] dailyTemperatures(int[] temperatures) {
//双指针 left right 等待天数:right-left
int[] daily=new int[temperatures.length];
for (int left=0;left<temperatures.length-1;left++){
int right=left+1;
while (temperatures[right]<=temperatures[left]){
right++;
if(right==temperatures.length){
right=left;
break;
}
}
daily[left]= right-left;
}
daily[temperatures.length-1]=0;
return daily;
}
}
class Solution {
public int[] dailyTemperatures(int[] temperatures) {
int len = temperatures.length;
//倒序遍历、动态规划
int max = temperatures[len-1];
int[] daily=new int[len];
for (int i = len-2; i >= 0; i--) {
if(temperatures[i]>=max){
max=temperatures[i];
}else {
int j = i+1;
while (temperatures[j]<=temperatures[i]){
j++;
}
daily[i]=j-i;
}
}
return daily;
}
}