← 返回 bytedance 的题目列表Valid Parentheses
类型:online_judge
Valid Parentheses
Given a string s containing only the characters '(', ')', '{', '}', '[', ']', determine whether the input string is valid.
Definition of valid
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every closing bracket must have a corresponding opening bracket of the same type before it.
Input
One line string s of length n.
Output
Print true if s is valid; otherwise print false.
Constraints
1 <= n <= 1e5
s consists only of (){}[].
Examples
s = "()" → true
s = "()[]{}" → true
s = "(]" → false
s = "([)]" → false
s = "{[]}" → true
Example
Input
()
Output
true