Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool f(string s){
- stack<char> p;
- for(int i=0;i<s.size();i++){
- if(s[i]=='(' || s[i]=='[')
- p.push(s[i]);
- else
- if(p.empty())
- return false;
- else
- if(((s[i]==')' && p.top()=='(') || (s[i]==']' && p.top()=='[')))
- p.pop();
- else
- return false;
- }
- if(!p.empty()) return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment