739. 每日温度
class Solution {
public int[] dailyTemperatures(int[] T) {
if (T == null || T.length == 0) return new int[]{};
Stack
int[] res = new int[T.length];
minStack.push(0);
for(int i = 1; i < T.length;i++){
while (!minStack.isEmpty() && T[minStack.peek()] < T[i]){
int daybefore = minStack.pop();
res[daybefore] = i - daybefore;
}
minStack.push(i);
}
return res;
//维护一个递减栈
//上一版的代码超时原因在于将天数一天天累加增加了复杂度 实际上数组索引已经代表了天数 题目还是做太少了
}
}

浙公网安备 33010602011771号