leetcode 20: Valid Parentheses
2015-07-03 11:58
267 查看
class Solution { public: bool isValid(string s) { stack<char> st; for(int i=0;i<s.length();i++) { if(s[i]=='('||s[i]=='['||s[i]=='{') st.push(s[i]); else { if(st.empty()) return false; switch(s[i]) { case ')': if(st.top()!='(') return false; else st.pop(); break; case ']': if(st.top()!='[') return false; else st.pop(); break; case '}': if(st.top()!='{') return false; else st.pop(); break; } } } if(!st.empty()) return false; return true; } };
相关文章推荐
- 对MTK平台的一些认识
- ISO-8859-1 To UTF8
- 文章标题
- Linux系统调用--------wait() 与 waitpid()
- Nginx 服务器安装及配置文件详解
- leetcode 19: Remove Nth Node From End of List
- 那些令人喷饭的代码注释
- linux系统 中Tomcat 报错 Could not initialize class java.awt.image.BufferedImage
- Java中JNI的使用详解第二篇:JNIEnv类型和jobject类型的解释
- 微软将会分批次进行升级Windows 10
- PHP5.3 htmlentities与json_encode的坑
- WIN7系统怎么关闭智能卡服务?
- leetcode 18: 4Sum
- 数组交换
- 数组交换
- Linux内核源码分析--内核启动之(2)Image内核启动(汇编部分)(Linux-3.0 ARMv7)
- leetcode 17: Letter Combinations of a Phone Number
- iOS--NSString---过滤换行符和空白字符
- [转]Android自定义捕获Application全局异常
- C#实例