Stack
Stack
1.单调栈
// 单调递增栈
for (int num : nums) {
while (!stack.isEmpty() && stack.peek() > num) {
stack.pop();
}
stack.push(num);
}
// 单调递减栈
for (int num : nums) {
while (!stack.isEmpty() && stack.peek() < num) {
stack.pop();
}
stack.push(num);
}2. 树的遍历顺序
3. 表达式转换
4. Simulate Recursion
Last updated