You are viewing a single comment's thread. Return to all comments →
C++ solution
bool isValid(string s) { int i=0,flag=0; stack<char> s1; while(s[i]!='\0') { if(s[i]=='(' ) s1.push(')'); else if(s[i]=='{' ) s1.push('}'); else if(s[i]=='[' ) s1.push(']'); else if(s1.empty() || s1.top()!=s[i]) { return false; } else s1.pop(); i++; } return s1.empty(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
C++ solution