#include<string>
#include<stack>
using namespace std;
class Solution {
public:
bool isValid(string s) {
if(s.empty()) return false;
stack<char> matchStack;
for(int i=0;i!=s.size();i++)
{
if(!matchStack.empty())
{
char frontChar=matchStack.top();
if(frontChar=='(' && s[i]==')'
|| frontChar=='[' && s[i]==']'
|| frontChar=='{' && s[i]=='}')
{
matchStack.pop();
}
else
{
matchStack.push(s[i]);
}
}
else
{
matchStack.push(s[i]);
}
}
return matchStack.empty();
}
};
Valid Parenthese
最新推荐文章于 2021-02-23 15:41:16 发布