We’re preparing your current view and syncing the latest data.
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if:
A single string s consisting of characters '(', ')', '{', '}', '[' and ']'.
Return true if the string is valid, otherwise return false.
1 <= s.length <= 10^4
Example 1
Input
"()"
Output
true
Explanation
Parentheses are properly closed in the correct order.
Example 2
Input
"()[]{}"Output
true
Explanation
Each type of bracket is properly closed in the correct order.
Example 3
Input
"(]"
Output
false
Explanation
The brackets are not closed by the same type.
Example 4
Input
"([)]"
Output
false
Explanation
The brackets are not closed in the correct order.
Example 5
Input
"{[]}"Output
true
Explanation
Brackets are nested and closed correctly.