#C1022. Balanced Bracket Sequence
Balanced Bracket Sequence
Balanced Bracket Sequence
Given a string (S) comprised solely of the characters '(' and ')', determine if it forms a balanced sequence of brackets. A bracket sequence is considered balanced if every opening bracket '(' has a corresponding closing bracket ')' and the pairs are properly nested. In other words, for every prefix of (S), the number of '(' must be at least as many as the number of ')'.
Return "Yes" if the sequence is balanced, otherwise return "No".
Examples:
Input: ()()
Output: Yes
inputFormat
A single line containing the string (S). It is guaranteed that (S) consists only of the characters '(' and ')'.
outputFormat
Print a single line containing "Yes" if the sequence of brackets is balanced, otherwise print "No".## sample
()
Yes