739.每日温度(栈M)
/** * @param {number[]} T * @return {number[]} */ var dailyTemperatures = function (T) { const len = T.length let res = new Array(len).fill(0) let stack = [] for (let i = 0; i < len; i++) { //如果栈不为空 且当前元素大于T下标为栈顶的元素 while(stack.length && T[i] > T[stack[stack.length - 1]]){ let j = stack.pop() res[j] = i - j } stack.push(i) } return res }