This question evaluates proficiency in sequence validation, paired-token matching, and the use of data structures to manage nested elements within strings.
Given a string s consisting only of the characters '(', ')', '{', '}', '[', ']', determine whether the string is valid.
A string is valid if:
s
(length
0..10^5
) containing only the six bracket characters.
true
if
s
is valid, otherwise return
false
.
s = "()"
→
true
s = "()[]{}"
→
true
s = "(]"
→
false
s = "([)]"
→
false
s = "{[]}"
→
true