Valid Parentheses
来源:互联网 发布:linux 软件 语言 中文 编辑:程序博客网 时间:2024/05/13 09:52
public class Solution { public boolean isValid(String s) { if (s == null || s.length() % 2 == 1) { return false; } Stack<Character> stack = new Stack<>(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '{' || c == '[' || c == '(') { stack.push(c); continue; } if (stack.isEmpty()) { return false; } char top = stack.pop(); if ((top == '{' && c == '}')|| (top == '[' && c == ']') || (top == '(' && c == ')')) { continue; } else { return false; } } if (stack.isEmpty()) { return true; } else { return false; } }}
0 0
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
- [扫描线 线段树] BZOJ 2161 布娃娃
- FragmentTransaction addToBackStack 无效问题
- HDU2012 素数判定
- MySQL数据库优化概述
- Valid Parentheses
- CSDN-markdown编辑器语法——字体、字号与颜色
- Ng机器学习 Week11 Application Example: Photo OCR
- Struts2—非UI标签—控制标签
- 图论
- Java Servlet Filter
- CC2530之DS18B20温度测量
- 纸牌游戏之六 游戏概述
- 比特币交易平台开发