LeetCode 20 Valid Parentheses
来源:互联网 发布:生鲜配送app源码 编辑:程序博客网 时间:2024/04/28 03:55
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 static boolean isValid(String s) {String[] strings = s.split("");Stack<String> stack = new Stack<String>();HashMap<String, String> map = new HashMap<String, String>();map.put("]", "[");map.put(")", "(");map.put("}", "{");for (String tmp : strings) {if (tmp.equals("{") || tmp.equals("(") || tmp.equals("[")) {stack.push(tmp);continue;}if (map.containsKey(tmp)) {if (stack.isEmpty() || !map.get(tmp).equals(stack.peek()))return false;stack.pop();}}if (stack.isEmpty()) return true;return false;}
0 0
- LeetCode 20: Valid Parentheses
- LeetCode(20) Valid Parentheses
- leetcode 20 Valid Parentheses
- Leetcode【20】:Valid Parentheses
- leetcode 20-Valid Parentheses
- [leetcode 20] Valid Parentheses
- [Leetcode] 20 - Valid Parentheses
- LeetCode | #20 Valid Parentheses
- leetcode.20-----------Valid Parentheses
- [leetcode] 20 Valid Parentheses
- leetcode-20 Valid Parentheses
- leetCode #20 Valid Parentheses
- leetcode 20 Valid Parentheses
- Leetcode 20 Valid Parentheses
- LeetCode 20 - Valid Parentheses
- LeetCode 20: Valid Parentheses
- leetcode-20 Valid Parentheses
- leetcode 20 -- Valid Parentheses
- 贪心1006
- tomcat性能调优
- 分析JAVA应用CPU占用过高的问题
- 解决MX4无法打印LOG
- iOS开发证书变成“此证书的签发者无效”解决方法
- LeetCode 20 Valid Parentheses
- java多线程小结,及解决应用挂死的问题
- Android Browser Share Feature
- 第四周项目18-游戏角色设计(2)
- (补)环境变量的配置以及eclipse的快捷键
- 3631:[JLOI2014]松鼠的新家
- 堆的概念及基本操作实现
- 二分查找算法(OC版--非递归实现)
- Bitmap与BiatmapFactory深入解析