We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
一维数组,要寻找任一个元素的右边(左边)第一个比自己大(小)的元素的位置时,第一时间想到用单调栈解题。
const dailyTemperatures = (T) => { const res = new Array(T.length).fill(0) const stack = [] for (let i = T.length - 1; i >= 0; i--) { while (stack.length && T[i] >= T[stack[stack.length - 1]]) { stack.pop() } if (stack.length) { res[i] = stack[stack.length - 1] - i } stack.push(i) } return res }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
单调栈
一维数组,要寻找任一个元素的右边(左边)第一个比自己大(小)的元素的位置时,第一时间想到用单调栈解题。
The text was updated successfully, but these errors were encountered: