33 单调栈

这是一种栈的诡异用法。当你需要知道当前值左/右边第一个比它大/小的值时,可以用这个栈。模板大概长这个样子:

monoStack = new Stack();

for (i 0 ~ len) {
    while (!stack.isEmpty() && curVal < stack.peek()) {
        stack.pop()
    }

    stack.push(curVal)
}

L126 Max Tree

84 Largest Rectangle in Histogram (L122) ctci 17.21 -- relate: 85 Maximal Rectangle

255 Verify Preorder Sequence in BST

449 Serialize and Deserialize BST- deserialize的非递归版本要用单调栈来把复杂度降低到O(n)

402 Remove K Digits

316 Remove Duplicate Letters

255 Verify Preorder Sequence in BST

739 Daily Temperatures

1673 Find the Most Competitive Subsequence

Last updated