1021. 删除最外层的括号(待补充)

个人注释

法一:

char * removeOuterParentheses(char * s) {
    int len = strlen(s);
    char *res = (char *)malloc(sizeof(char) * len);
    char *stack = (char *)malloc(sizeof(char) * (len / 2));
    int pos = 0, top = 0;
    for (int i = 0; i < len; i++) {
        char c = s[i];
        if (c == ')') {     //进stack栈
            top--;
        }
        if (top > 0) {      //如果stack栈不为空,及此时c为 原语字符串中一个字符 将其存入字符串res
            res[pos++] = c;
        }
        if (c == '(') {     //出stack栈
            stack[top++] = c;
        }
    }
    free(stack);
    res[pos] = '\0';    //结束res字符串
    return res;
}

法二:

作者:力扣官方题解
链接:https://leetcode.cn/problems/remove-outermost-parentheses/solutions/1520365/shan-chu-zui-wai-ceng-de-gua-hao-by-leet-sux0/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值