#C8593. Valid Parenthesis Expression
Valid Parenthesis Expression
Valid Parenthesis Expression
Given a string S
consisting only of the characters '(' and ')', determine whether it is a valid parenthesis expression.
A valid expression satisfies the following condition in LaTeX:
\( \text{For every prefix of the string, the number of '(' is not less than the number of ')', and the total counts are equal.} \)
You can think of it as checking if every opening bracket has a corresponding closing bracket in the correct order.
inputFormat
The input is read from standard input (stdin) and consists of a single line containing the string S
, where S
contains only '(' and ')'.
outputFormat
The output, written to standard output (stdout), should be a single line with either True
if the string is a valid parenthesis expression, or False
otherwise.
()
True
</p>