easy c++


  • 0
    J
        bool check(string s, char sign){
            int stk = 0, cnt = 0;
            for(char &c : s){
                if(c == sign) stk ++;
                else if(c == '*') cnt++;
                else{
                    if(stk > 0) stk--;
                    else if(cnt) cnt--;
                    else return false;
                }
            }
            return true;
        }
        
        bool checkValidString(string s) {
            if( !check(s,'(') ) return false;
            reverse(s.begin(), s.end());
            return check(s, ')');
        }
    

Log in to reply
 

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