[Leetcode] Valid Parentheses
来源:互联网 发布:天猫优质男装品牌知乎 编辑:程序博客网 时间:2024/06/06 05:57
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) { int len=s.length(); char[] sym=new char[len]; int count=0; for(int i=0;i<len;i++) { switch (s.charAt(i)) { case '(': sym[count]='('; count++; break; case ')': count--; if(count<0) return false; if(sym[count]!='(') return false; break; case '[': sym[count]='['; count++; break; case ']': count--; if(count<0) return false; if(sym[count]!='[') return false; break; case '{': sym[count]='{'; count++; break; case '}': count--; if(count<0) return false; if(sym[count]!='{') return false; break; default: break; } } if(count!=0) return false; else return true; }}
0 0
- LeetCode: Valid Parentheses
- LeetCode: Longest Valid Parentheses
- LeetCode: Valid Parentheses
- LeetCode Longest Valid Parentheses
- [Leetcode] Valid Parentheses
- LeetCode: Longest Valid Parentheses
- [Leetcode] Longest Valid Parentheses
- LeetCode : Valid Parentheses
- [leetcode]longest Valid Parentheses(!!)
- Leetcode: Valid Parentheses
- leetcode 52: valid parentheses
- [Leetcode] Longest Valid Parentheses
- leetcode Longest Valid Parentheses
- 【leetcode】Valid Parentheses
- 【leetcode】Longest Valid Parentheses
- [LeetCode]Longest Valid Parentheses
- [LeetCode]Valid Parentheses
- LeetCode-Valid Parentheses
- 头像上传
- 机器视觉与计算机视觉的数学基础分析与感想
- MinGW配置pthread环境(转)
- git - git 命令使用笔记
- 超大01背包(hdu 5887)
- [Leetcode] Valid Parentheses
- Makefile中origin函数
- Unity客户端架构-UIContainer
- [Android]Activity启动过程
- 面向对象程序设计上机练习九(对象指针)
- 有刷、有感和无刷无感电机的使用心得
- 不依赖storyboard实现ViewController跳转和传参
- 微信native扫码支付
- 一、安卓预备知识