Valid Parentheses
来源:互联网 发布:深圳淘宝运营助理招聘 编辑:程序博客网 时间:2024/06/08 10:50
public class Solution { public boolean isValid(String s) { if (s == null || s.isEmpty()) return false; Stack<Character> chars = new Stack<Character>(); chars.push(s.charAt(0)); for (int i=1; i<s.length(); i++){ char c = s.charAt(i); if (c=='(' || c=='[' || c=='{'){ chars.push(c); }else{ if (chars.isEmpty()) return false; char curr = chars.peek(); if ((c==')' && curr=='(') || (c==']' && curr=='[') || (c=='}' && curr=='{')){ chars.pop(); }else{ return false; } } } return chars.isEmpty(); }}
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
- Android 分享功能,过滤掉不需要的组件,解决出现“Android系统“问题
- xcode工程的文件夹类型 folder References group
- 超越Administrator的权限
- 关于Handler、 Looper 、MessageQueue的认识
- 必须掌握的八个DOS命令
- Valid Parentheses
- PDU编码规则
- 个人感悟
- HDU1269(Tarjan算法)
- webmagic_dependency
- java设计模式之单例模式写法,懒汉,饿汉,双检锁
- 键-值观察(KVO模式)
- 初学者怎样才能开发出高效的J2EE系统
- 如何让表格的奇数行和偶数行具有不同的背景颜色