12 lines!!!!!!!!


  • -1
    Y

    bool isValid(string s) {
    bool runFlag=true;
    if(s.empty()) return runFlag;
    while(runFlag){
    int k=s.size();
    for(int i=k-1;i>0;i--)
    if((s[i]==')'&&'('==s[i-1])||((s[i]=='}'&&'{'==s[i-1]))||((s[i]==']'&&'['==s[i-1])))s.erase(i-1,2);
    if(k<=s.length())break;//runFlag=false;
    }
    if(s.empty()) return true;
    else return false;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.