# Problems
# Pairing
# Monotonic Stack
# LeetCode
# 20. Valid Parentheses
Using a stack
1 | |
# 32. Longest Valid Parentheses
Only matched parenthesis should count, we could save the indexes of the parenthesis in stack and make a subtraction.
We store every index in the stack. The unpoped indexes are bad indexes. We only need to subtract them using current index to find out the longest contiguous valid parenthesis.
1 | |