#K15571. Valid Parentheses Checker
Valid Parentheses Checker
Valid Parentheses Checker
Given a string containing only the characters '(' and ')', determine if the string forms a valid parentheses sequence.
A string is considered valid if it satisfies the following conditions:
- Every '(' has a corresponding ')'.
- Every ')' has a corresponding '('.
- An opening parenthesis '(' appears before its corresponding closing parenthesis ')'.
This can also be expressed in \( \LaTeX \) as follows:
\( \text{A string } s \text{ is valid if } \forall i \, (s[i] = '(' \Rightarrow \exists j > i \text{ such that } s[j] = ')') \) and the reverse holds true.
Your task is to read the input from standard input and output True
if the string is valid; otherwise, output False
.
inputFormat
The input consists of a single line of text containing a string made up only of the characters '(' and ')'.
outputFormat
Output a single line with either 'True' or 'False' (without quotes), indicating whether the input string is a valid parentheses sequence.## sample
()
True
</p>