Valid Parentheses(java实现)
来源:互联网 发布:大众软件停刊了吗 编辑:程序博客网 时间:2024/05/17 02:14
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
public class Solution{public static boolean isValid(String s){char[] ch = s.toCharArray();Stack<Character> stack = new Stack<>();for (int i = 0; i < ch.length; i++){if (stack.empty()){stack.push(ch[i]);}else{Character ch1 = stack.peek();Character ch2 = ch[i];if (ch1.equals('(') && ch2.equals(')') || ch1.equals('{') && ch2.equals('}')|| ch1.equals('[') && ch2.equals(']'))stack.pop();elsestack.push(ch[i]);}}if (stack.empty())return true;elsereturn false;}}
0 0
- Valid Parentheses(java实现)
- LeetCode中Valid Parentheses的JAVA实现
- [Leetcode] Valid Parentheses (Java)
- Longest Valid Parentheses Java
- Valid Parentheses (Java)
- Longest Valid Parentheses (Java)
- Valid Parentheses leetcode java
- Longest Valid Parentheses Java
- [LeetCode][Java] Valid Parentheses
- 【leetcode】Valid Parentheses【java】
- Valid Parentheses Java
- (java) Valid Parentheses
- Valid Parentheses LeetCode java
- leetcode:Valid Parentheses 【Java】
- LeetCode : Valid Parentheses [java]
- LeetCode-JAVA-Valid Parentheses
- leetcode Valid Parentheses(Java)
- 20. Valid Parentheses(java)
- thinikPHP的学习之路(一)
- UVA 1329 Corporative Network(并查集)
- 发现代码
- UITableView的重用池优化
- Linux下创建、查看、提取和修改静态库(*.a)
- Valid Parentheses(java实现)
- 关于python的事件编程
- JavaWeb初级学习 之 HTML
- asp 跳转到外链url,二级跳转到站外链接的代码
- 年鉴网
- 深入C++的new
- Android设置圆形组件以及在组件中设置图标或文字的2中方法
- Tomcat的安装与配置
- JQuery easyui datagrid简单使用(一)