Valid Parentheses
Problem statement
Given a string s containing only (, ), [, ], {, and }, return whether it is valid.
A string is valid when every opening bracket is closed by the same bracket type and brackets close in the correct nested order. The empty string is valid.
Function
isValidParentheses(s: String) → booleanExamples
Example 1
s = "([]{})"return = trueEvery bracket closes in the reverse order in which it opened.
Example 2
s = "([)]"return = falseThe closing parenthesis appears before the square bracket is closed.
Constraints
0 <= s.length <= 100000.scontains only the six bracket characters listed above.