Londor13417

Untitled

Jun 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. bool f(string s){
  2. stack<char> p;
  3. for(int i=0;i<s.size();i++){
  4. if(s[i]=='(' || s[i]=='[')
  5. p.push(s[i]);
  6. else
  7. if(p.empty())
  8. return false;
  9. else
  10. if(((s[i]==')' && p.top()=='(') || (s[i]==']' && p.top()=='[')))
  11. p.pop();
  12. else
  13. return false;
  14. }
  15. if(!p.empty()) return false;
  16. return true;
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment