#C12813. Longest Valid Parentheses
Longest Valid Parentheses
Longest Valid Parentheses
Given a string s
consisting only of the characters '(' and ')', determine the length of the longest valid (well-formed) parentheses substring. A valid substring is one where every opening parenthesis has a corresponding closing parenthesis and the parentheses are properly nested.
For example, for the input "(()"
, the longest valid substring is "()"
with a length of 2.
Note: The solution should read the input from standard input (stdin) and print the result to standard output (stdout).
inputFormat
A single line containing the string s
, which contains only the characters '(' and ')'.
Example:
()(()))
outputFormat
Output a single integer representing the length of the longest valid (well-formed) parentheses substring.
Example:
4## sample
()
2
</p>