这个问题可以通过使用栈(Stack)来解决。主要思想是:
给定一个只包括 '(',')','{','}','[',']' 的字符串 s,判断字符串是否有效。
有效字符串需满足:
输入一个字符串 s。
输出 "true" 或 "false",表示字符串是否有效。不用考虑大小写。
输入
()
输出
true
输入
()[]{}
输出
true
输入
(]
输出
false
输入
([])
输出
true
By signing up a CodeFun2000 universal account, you can submit code and join discussions in all online judging services provided by us.