Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 619 Bytes

1021. Remove Outermost Parentheses.md

File metadata and controls

25 lines (25 loc) · 619 Bytes

题目

1021. Remove Outermost Parentheses

思路

4ms 94.26%

代码

class Solution {
public:
    string removeOuterParentheses(string S) {
        int count=1,beg=0;
        string ans;
        for(int i=1;i<S.size();i++){
            if(S[i]=='(')count++;
            if(S[i]==')')count--;
            if(count==0){
                string tmp=S.substr(beg,i-beg+1);
                tmp=tmp.substr(1,tmp.size()-2);
                ans+=tmp;
                beg=i+1;
            }
        }
        return ans;
    }
};