LeetCode中Valid Parentheses的JAVA实现
来源:互联网 发布:在linux中安装oracle 编辑:程序博客网 时间:2024/06/05 11:35
先上题目:
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 class Solution {
public boolean isValid(String s) {
LinkedList<Character> stack = new LinkedList<Character>();
for(char c:s.toCharArray())
{
if(!stack.isEmpty())
{
if(stack.peek()==40&&c==41||stack.peek()==91&&c==93||stack.peek()==123&&c==125)
{
stack.pop();
}else
{
stack.push(c);
}
}else
{
stack.push(c);
}
}
return stack.isEmpty()?true:false;
}
}
0 0
- LeetCode中Valid Parentheses的JAVA实现
- [Leetcode] Valid Parentheses (Java)
- Valid Parentheses leetcode java
- [LeetCode][Java] Valid Parentheses
- 【leetcode】Valid Parentheses【java】
- Valid Parentheses LeetCode java
- leetcode:Valid Parentheses 【Java】
- LeetCode : Valid Parentheses [java]
- LeetCode-JAVA-Valid Parentheses
- leetcode Valid Parentheses(Java)
- Leetcode Valid Parentheses(java)
- Valid Parentheses(java实现)
- C实现 LeetCode->Valid Parentheses
- [Leetcode] Longest Valid Parentheses (Java)
- LeetCode – Valid Parentheses (Java)
- [LeetCode][Java] Longest Valid Parentheses
- [leetcode-20]Valid Parentheses(java)
- LeetCode 20 : Valid Parentheses (Java)
- 数据结构系列之快速排序详解
- Vijava学习笔记之(为指定的SCSI控制器,添加关联磁盘。主要针对虚拟机)
- 【MAC技术组】Mac忘记登录密码的4种解决方法
- 在windows系统制作mac os的U盘启动盘
- kettle5 eclipse中查看编译原码
- LeetCode中Valid Parentheses的JAVA实现
- Socket非阻塞连接过程
- 虚拟化之VMM了解
- 科技收藏
- 简单实现Shiro单点登录(自定义Token令牌)
- Maven 安装本地jar
- python异常处理
- 危险系数
- MFC隐藏和显示一个控件的方法