33 单调栈
这是一种栈的诡异用法。当你需要知道当前值左/右边第一个比它大/小的值时,可以用这个栈。模板大概长这个样子:
monoStack = new Stack();
for (i 0 ~ len) {
while (!stack.isEmpty() && curVal < stack.peek()) {
stack.pop()
}
stack.push(curVal)
}
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)
Previous443 String Compression & ctci189 1 point 6 String CompressionNext1673 Find the Most Competitive Subsequence
Last updated
Was this helpful?