题解 | #每日温度#
每日温度
http://www.nowcoder.com/practice/1f54e163e6944cc7b8759cc09e9c78d8
又是0.00% 哼(¬︿̫̿¬☆)
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param temperatures int整型一维数组
* @return int整型一维数组
*/
public int[] temperatures (int[] temperatures) {
// write code here
int len=temperatures.length;
int[] res=new int[len];
Stack<Integer> stacks=new Stack<>();
Stack<Integer> orders=new Stack<>();
int index=len-1;
while(index!=-1){
if(stacks.empty()){
res[index]=0;
stacks.push(temperatures[index]);
orders.push(index);
index--;
}else{
if(temperatures[index]<stacks.peek()){
res[index]=orders.peek()-index;
stacks.push(temperatures[index]);
orders.push(index);
index--;
}else{
while(temperatures[index]>=stacks.peek()){
stacks.pop();
orders.pop();
if(stacks.empty()){
break;
}
}
}
}
}
return res;
}
}