Valid Parentheses
来源:互联网 发布:淘宝开店保证金好退吗 编辑:程序博客网 时间:2024/04/29 11:15
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.
#include<iostream>#include<vector>#include<string>#include<stack>using namespace std;bool isValid(string s) {if (s.empty())return true;stack<char>CharStack;for (int i = 0; i != s.size();++i){if (s[i] == '(' || s[i] == '{' || s[i] == '[')CharStack.push(s[i]);else{if (CharStack.empty())return false;switch (s[i]){case ')':if (CharStack.top() == '(')CharStack.pop();elsereturn false;break;case ']':if (CharStack.top() == '[')CharStack.pop();elsereturn false;break;case'}':if (CharStack.top() == '{')CharStack.pop();elsereturn false;break;default:break;}}}return CharStack.empty();}
0 0
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Linux设备驱动探究第1天----spi驱动(1)
- hdoj 2612 Find a way
- Android抽屉效果的实现(不挤压,不覆盖)
- [省选前题目整理][BZOJ 2754][SCOI 2012]喵星球上的点名(后缀数组)
- mysql查询更新时的锁表机制分析
- Valid Parentheses
- C语言和设计模式(之组合模式)
- keil中忽略特定警告的方法
- String 构造,析构,复制,拷贝构造函数
- hdoj 1166 敌兵布阵 【单点更新+区间求和】 【线段树】 【树状数组】
- python中的__new__()方法
- java进阶 ------ IO流
- 拼接url
- C语言和设计模式(之模板模式)