There is no specific application through the function STL template library, here found a relatively simple, the core is the use of the stack, advanced stack of a legal character behind the character if left bracket to then into the stack, if it is left bracket verify whether the match the symbol stack, the stack if the matching symbols from the stack, continue to determine subsequent characters until the stack is empty, if no match is empty, return false
classSolution{public:boolisValid(string s){if(s.length()==0)returntrue;if(s.length()==1)returnfalse;
stack<char>ss;int index =0;while(index<s.length()){if(s[index]=='('||s[index]=='{'||s[index]=='[') ss.push(s[index]);elseif(s[index]==')'){if(ss.empty()||ss.top()!='(')returnfalse;
ss.pop();}elseif(s[index]=='}'){if(ss.empty()||ss.top()!='{')returnfalse;
ss.pop();}elseif(s[index]==']'){if(ss.empty()||ss.top()!='[')returnfalse;
ss.pop();}++index;}if(!ss.empty())returnfalse;returntrue;}};