LeetCode刷题(C++)——Valid Parentheses(Easy)
来源:互联网 发布:建筑测量学知乎 编辑:程序博客网 时间:2024/06/05 13:34
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.
class Solution {public: bool isValid(string s) { if ((s.size() & 1) == 1)return false;stack<char> p;for (auto x : s){if (x == '(') p.push(')');else if (x == '{')p.push('}');else if (x == '[')p.push(']');else{if (!p.empty()){char temp = p.top();if (temp == x)p.pop();elsereturn false;}elsereturn false;}}if (!p.empty())return false;elsereturn true; }};
0 0
- LeetCode刷题(C++)——Valid Parentheses(Easy)
- 【leetcode】Valid Parentheses(easy)
- LeetCode-Easy刷题(5) Valid Parentheses
- Leetcode笔记整理—easy篇—Valid Parentheses
- 【leetcode】20. Valid Parentheses(Python & C++)
- 【LeetCode算法练习(C++)】Valid Parentheses
- [Leetcode 20, Easy] Valid Parentheses
- 【Leetcode-Easy-20】 Valid Parentheses
- [LeetCode] 020. Valid Parentheses (Easy) (C++/Java/Python)
- Easy 5 Valid Parentheses(20)
- 【leetcode】String——Longest Valid Parentheses(32)
- leetcode 32. Longest Valid Parentheses——(use stack)
- LeetCode 20 — Valid Parentheses(C++ Java Python)
- LeetCode——Valid Parentheses
- 【leetcode】20—valid parentheses
- LeetCode(20)Valid Parentheses
- leetcode(20. Valid Parentheses)
- LeetCode(49)-Valid Parentheses
- 官方DrawerLayout的简单使用
- 第四十三讲项目二 文件中的符号个数
- SCOI2012 喵星球上的点名 BZOJ 2754
- 【记录】网络连接失败
- hpuoj1298: 杨辉三角2
- LeetCode刷题(C++)——Valid Parentheses(Easy)
- Linux 命令行while do
- ArcGIS不能创建几何网络
- Http协议
- Android使用ViewPager+Fragment实现标签分页
- 类加载机制
- Java递归解决全排列问题
- Ajax请求步骤,原生js代码
- Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual tha