20. Valid Parentheses(stack)
来源:互联网 发布:热传导分析软件 编辑:程序博客网 时间:2024/05/22 04:24
problem
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.
answer
class Solution {public: bool isValid(string s) { stack<char> pStack; int i = 0; // if(s.size() == 1){ // return false; // } while(s[i] != '\0'){ // if(pStack.empty() && (s[i]==')') || s[i]==']' || s[i]=='}'){ // return false; // } if(s[i] == '(' || s[i] == '[' || s[i] == '{'){ pStack.push(s[i++]); } else if(!pStack.empty() && ((s[i] == ')' && pStack.top() == '(') || (s[i] == ']' && pStack.top() == '[') || (s[i] == '}' && pStack.top() == '{'))){ pStack.pop(); i++; } else{ return false; } } if(!pStack.empty()){ return false; } return true; }};
time:0ms
0 0
- 20. Valid Parentheses(stack)
- 20. Valid Parentheses-Stack用法
- 20.Valid Parentheses(Stack-Easy)
- [Leetcode] 20. Valid Parentheses(Stack)
- LeetCode[stack]: Valid Parentheses
- stack--Longest Valid Parentheses
- [leetcode #20 stack]Valid Parentheses
- Lintcode Stack 423 Valid Parentheses
- 20. Valid Parentheses--合法的括号组合(使用stack)
- LeetCode 20. Valid Parentheses
- [LeetCode] 20.Valid Parentheses
- LeetCode --- 20. Valid Parentheses
- LeetCode 20.Valid Parentheses
- [Leetcode] 20. Valid Parentheses
- 20.Valid Parentheses
- 20.Valid Parentheses
- 20. Valid Parentheses
- 【leetcode】20. Valid Parentheses
- ubuntu下 adb devices找不到devices
- 401 biharmonic deformation
- 012-矩阵链相乘-动态规划-《算法设计技巧与分析》M.H.A学习笔记
- Android中监听Home键的4种方法总结
- JNI编程(AndroidStudio)
- 20. Valid Parentheses(stack)
- mysql 5.7.13 在ubuntu上的安装以及部分简单说明
- 带圆点标示的ViewPager
- placeholder IE兼容问题
- android studio 一些使用问题
- 编写一个删除C语言程序中所有注释语句的程序
- SpringMVC日期绑定
- JavaWeb学习总结(三)——Tomcat服务器学习和使用(二)
- JAVA配置文件的读取