Correct solution:

#include <stack> class Solution { public: bool isValid(string s) { stack<char> p; char a, b, c; if (s.length() == 1) return false; for (int i = 0; i < s.length(); i++){ if (s[i]=='(' || s[i]=='{' || s[i]=='[') p.push(s[i]); else if(p.empty() == false){ switch (s[i]){ case ')': a = p.top(); p.pop(); if (a != '(') return false; break; case '}': b = p.top(); p.pop(); if (b != '{') return false; break; case ']': c = p.top(); p.pop(); if (c != '[') return false; break; } //if (p.empty() == false) // return false; } else{ p.push(s[i]); } } return (p.empty()); } };