Valid Parentheses
Given a string s containing only the characters '(', ')', '{', '}', '[', and ']', determine if the input string is valid.
A string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- Every close bracket has a corresponding open bracket of the same type.
Return true if s is valid, otherwise return false.
Example 1
Input
s = "()"Output
trueThe single pair of parentheses is properly opened and closed.
Example 2
Input
s = "()[]{}"Output
trueEach bracket type is properly opened and closed in order.
Constraints
- 1 <= s.length <= 10^4
- s consists of parentheses only: '(', ')', '{', '}', '[' and ']'