17 solutions

  • 0
    @ 2022-1-1 22:50:24
    #include<bits/stdc++.h>
    using namespace std; 
    stack <int> st;
    string t;
    int main()
    {
        cin>>t;
        int len = t.size();
        int flag = 0;
        for(int i=0;i<len;i++){
            if(t[i] == '('){
               
                st.push(t[i]);
            }
            else if(t[i] == ')'){
                if(st.empty()){
                    flag = 1;break;
                }
                else{
                    if(t[i] == ')' && st.top() == '(') st.pop();
                }
            }
        }
    
        if(st.size() || flag){
        	cout<<"NO";
    	}
        else{
        	cout<<"YES";
    	}
        return 0;
    }
    
    
    

    Information

    ID
    289
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    5
    Tags
    # Submissions
    234
    Accepted
    87
    Uploaded By