Valid Parentheses
来源:互联网 发布:湖北省融资租赁数据 编辑:程序博客网 时间:2024/05/22 11:52
class Solution {
public:
bool isValid(string s) {
stack<char> charstack;
size_t i=0;
while(i<s.length())
{
char c=s[i];
if(c!=')'&&c!='}'&&c!=']')
charstack.push(c);
else
{
if(charstack.size()==0)
return false;
char pre=charstack.top();
switch(c)
{
case ')':
if(pre=='(')
charstack.pop();
else
return false;
break;
case '}':
if(pre=='{')
charstack.pop();
else
return false;
break;
case ']':
if(pre=='[')
charstack.pop();
else
return false;
break;
}
}
i++;
}
if(charstack.size()==0)
return true;
else
return false;
}
};
public:
bool isValid(string s) {
stack<char> charstack;
size_t i=0;
while(i<s.length())
{
char c=s[i];
if(c!=')'&&c!='}'&&c!=']')
charstack.push(c);
else
{
if(charstack.size()==0)
return false;
char pre=charstack.top();
switch(c)
{
case ')':
if(pre=='(')
charstack.pop();
else
return false;
break;
case '}':
if(pre=='{')
charstack.pop();
else
return false;
break;
case ']':
if(pre=='[')
charstack.pop();
else
return false;
break;
}
}
i++;
}
if(charstack.size()==0)
return true;
else
return false;
}
};
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
- Hibernate七部曲(三)hql
- iOS 获取当前APP在APPStore上的版本信息等
- CocoaPods 安装 iOS,简单易懂!!
- C语言的位操作符可以用来表示集合的运算
- C#之ArcGIS二次开发
- Valid Parentheses
- Springmvc知识二细节-----@ModelAttribute
- 求字符串中不包含重复字符的最长子串的长度
- Halcon学习笔记(三)---数据类型
- 图片的二次采样
- linux硬件软件操作系统查看
- CURL常用命令
- div垂直居中
- 解决RedHat中yum命令未注册问题