汤姆torn

关注

1021. 删除最外层的括号

汤姆torn

关注

阅读 127

2022-01-31

解法1:计数器

class Solution {
public:
    string removeOuterParentheses(string s) {
         string res;
         for(int i=0,cnt=0,j=0;i<s.size();i++)
         {
             if(s[i]=='(') cnt++;
             else if(--cnt==0)
             {
                 res+=s.substr(j+1,i-j-1);
                 j=i+1;
             }
         }
         return res;
    }
};

相关推荐

心存浪漫

每日一题 leetcode 1021. 删除最外层的括号 java

心存浪漫 136 0 0

静悠

1021. 删除最外层的括号 : 简单双指针模拟题

静悠 130 0 0

四月Ren间

删除最外层的括号

四月Ren间 156 0 0

飞进科技

【leetcode 】 删除最外层的括号

飞进科技 112 0 0

一点读书

LeetCode简单题之删除最外层的括号

一点读书 164 0 0

敬亭阁主

每日一题——LeetCode1021删除最外层括号&1047消除字符串相邻重复字符串

敬亭阁主 10 0 0

young_d807

1021. 个位数统计 (15)

young_d807 68 0 0

心如止水_c736

【Leetcode_easy】1021. Remove Outermost Parentheses

心如止水_c736 58 0 0

一葉_code

【LeetCode】1021. Best Sightseeing Pair 最佳观光组合(Python)

一葉_code 51 0 0

彭维盛

【leetcode_easy_stack】1021. Remove Outermost Parentheses

彭维盛 70 0 0

精彩评论(0)

0 0 举报