Problem · String
Valid Parentheses
Learn this problemProblem statement
Given a string s containing only the bracket characters (, ), [, ], {, and }, determine whether it is valid.
A string is valid when every opening bracket is closed by the same type of bracket and brackets close in the reverse order in which they were opened. The empty string is valid.
Return true if s is valid; otherwise, return false.
Function
isValidParentheses(s: String) → booleanExamples
Example 1
s = "()[]{}"return = trueEach opening bracket is immediately followed by its matching closing bracket.
Example 2
s = "([{}])"return = trueThe brackets are properly nested and close in reverse opening order.
Example 3
s = "([)]"return = falseThe closing parenthesis appears before the nested square bracket is closed.
Constraints
0 <= s.length <= 100000.- Every character of
sis one of()[]{}.