Valid Bracket Sequence
Problem statement
Given a string s containing only the bracket characters ()[]{}, determine whether it is a valid bracket sequence.
Every opening bracket must be closed by the same bracket type, and closing brackets must appear in the reverse order of their matching openings. A closing bracket without a prior unmatched opening is invalid. The empty string is valid.
Function
isValidBracketSequence(s: String) → booleanExamples
Example 1
s = "([]){}"return = trueEach closer matches the newest unmatched opener of the same type.
Example 2
s = "([)]"return = falseThe closing parenthesis arrives while the square bracket is still open.
Example 3
s = "((("return = falseThree opening brackets remain unmatched.
Example 4
s = ""return = trueThere are no unmatched brackets in the empty sequence.
Constraints
0 <= s.length <= 100000.- Every character is one of
(,),[,],{, or}.