题目摘要
给一个只含有”(“, “)”, “[“, “]”, “{“, “}”的字符串,判断括号合并顺序是否正确
解法
Stack
注意
* 奇数个字符肯定错误
原题
Given a string containing just the characters '('
, ')'
, '{'
, '}'
, '['
and ']'
, determine if the input string is valid.
The brackets must close in the correct order, "()"
and "()[]{}"
are all valid but "(]"
and "([)]"
are not.
Subscribe to see which companies asked this question