[leetcode]Valid Parentheses题解
来源:互联网 发布:java jdk 编辑:程序博客网 时间:2024/05/17 08:27
描述
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
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.
利用一个栈来保存前括号,然后有后括号来时弹出栈顶来判断
bool isValid (string s){stack<char> k;for (string::size_type index =0;index!=s.size();++index){if (s[index]=='('||s[index]=='{'||s[index]=='['){k.push(s[index]);}else{switch(s[index]){case ')':if (!k.empty()&&k.top()=='('){k.pop();} else return false; break;case '}':if (!k.empty()&&k.top()=='{') { k.pop(); } else return false; break;case ']':if (!k.empty()&&k.top()=='[') { k.pop(); } else return false; break;}}}return k.empty();}
0 0
- LeetCode题解:Valid Parentheses
- [题解][LeetCode][Valid Parentheses]
- [leetcode]Valid Parentheses题解
- LeetCode题解:Valid Parentheses
- LeetCode题解:Valid Parentheses
- LeetCode题解:Longest Valid Parentheses
- [leetcode]Longest Valid Parentheses题解
- leetcode 题解 || Valid Parentheses 问题
- LeetCode题解:Longest Valid Parentheses
- leetcode题解-20. Valid Parentheses
- LeetCode 题解(78): Valid Parentheses
- LeetCode 题解(111): Longest Valid Parentheses
- LeetCode题解——Valid Parentheses
- Leetcode题解14 20. Valid Parentheses
- LeetCode Algorithms 32. Longest Valid Parentheses 题解
- leetcode题解-32. Longest Valid Parentheses
- Valid Parentheses python题解
- 20. Valid Parentheses题解
- 欧几里得算法
- 如何让CFree5.0支持C++11
- 本地无客户端远程连接oracle服务器
- unity 滑动条控制动画播放代码
- Android学习(13)-跨程序共享数据
- [leetcode]Valid Parentheses题解
- 中水处理设备:一体化中水处理设备特点阐述
- NSURLConnection 向服务器发送post请求
- Chapter03-跨进程共享内核对象
- quick cocos2dx 2.2.5Plus中无解的问题
- Day17-进度条控件
- 环境配置
- 【编程之美】1.1让cpu占用率曲线听你指挥
- 16. 3Sum Closest Leetcode Python