Balanced Parentheses
You are given a string consisting only of the characters (, ), [, ], {, and }.
A string is considered balanced if:
- Every opening bracket is closed by the same type of bracket.
- Brackets are closed in the correct order.
Determine whether the given string is balanced.
Input
A single line containing the string s.
Output
Print YES if s is balanced, otherwise print NO.
Constraints
- 1≤∣s∣≤2⋅105
- s contains only
(,),[,],{,}
Example 1
()[]{}
YES
Example 2
([{}])
YES
Example 3
([)]
NO
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.