LeetCode Valid Parentheses非常简单的解法
来源:互联网 发布:霓虹灯led动画软件 编辑:程序博客网 时间:2024/05/15 23:53
/******************************************
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> st; for(char c : s){ if(c == '('|| c == '{' || c == '['){ st.push(c); }else{ if(st.empty()) return false; if(c == ')' && st.top() != '(') return false; if(c == '}' && st.top() != '{') return false; if(c == ']' && st.top() != '[') return false; st.pop(); } } return st.empty(); }
0 0
- LeetCode Valid Parentheses非常简单的解法
- Longest Valid Parentheses[leetcode] 的三种解法
- LeetCode Longest Valid Parentheses的O(N)解法
- leetcode Longest Valid Parentheses O(n)解法
- leetcode -- Valid Parentheses -- 简单重点
- LeetCode #20 Valid Parentheses C C++ Java解法
- [LeetCode P32] Longest Valid Parentheses 四种解法
- 【栈/DP】LeetCode 32. Longest Valid Parentheses 八种解法
- LeetCode Partition List 非常简单易懂的解法
- Valid Parentheses问题及解法
- 【LeetCode】- Valid Parentheses(有效的括号)
- LeetCode中Valid Parentheses的JAVA实现
- LeetCode-20-Valid Parentheses(有效的括号)
- LeetCode: Valid Parentheses
- LeetCode: Longest Valid Parentheses
- LeetCode: Valid Parentheses
- LeetCode Longest Valid Parentheses
- [Leetcode] Valid Parentheses
- 已知先序中序求树的高度或叶子数
- jquery遍历table元素
- 父类与子类析构与函数调用关系
- 参数的魅力
- UI_UIToolbar
- LeetCode Valid Parentheses非常简单的解法
- java程序向mysql数据表插入数据时中文乱码问题
- Git学习日记
- 学技术总是浮躁不安,最近想看看佛经名句,使内心稍许安定
- Java的23种设计模式01-单例模式(Singleton)
- caffe LMDB 库学习
- J2EE 1.3 Tomcat的安装
- android使用ViewPager实现引导页效果
- Android 蓝牙开发 博客链接