Given a string containing only '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
This solution uses a stack to store indices of parentheses. It scans the string once and calculates the maximum length of a valid parentheses substring.
O(n)
O(n)
javac Solution.java
java Solution