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.
public boolean isValid(String s) {
if (s.length() % 2 != 0)
return false;
char[] characters = new char[s.length()];

该博客主要讨论LeetCode第20题——如何判断输入字符串中的括号是否有效。内容提到了解决方案必须确保括号按正确顺序关闭,如'()'和'()[]{}'有效,但'(]'和'([)]'无效。作者提到自己的解法较为笨拙,推荐读者查看其他更优解法,特别是使用系统栈的方法。
订阅专栏 解锁全文
325

被折叠的 条评论
为什么被折叠?



