1021.removeOutermost-parentheses

分析:去除最外一层的括弧;

首先从最简单的开始分析(),对于这样单一的括弧,去除最外层,就是把字符串最开始的最后的元素去除即可;在复杂一点()(),那么分开看成两个()+(),用一个temp字符串临时存放前面一个,当遍历到),即形成一个完整的括弧,那么删去它的最外层括弧,然后将临时的字符串temp清空继续遍历下一个完整的括弧;再继续(())(),对于前一部分 ,首先我们要找到(()),这里可以利用栈的思想,栈可以用于括号匹配,遇到(入栈,遇到)出栈,当栈为空时说明一个括弧遍历完成,那么再去除最外层的();

1、声明两个变量,temp(存放子括弧),result(最后结果);声明栈

2、遍历S字符串的每个元素,当==(,入栈,==)出栈;

3、栈为空,部分子括弧遍历结束,将最外层()去除,加入到result中;

class Solution {
public:
    string removeOuterParentheses(string S) {
        stack<char> s1;
        string temp;
        string result;
        int len = S.length();
        for(int i=0;i<len;i++){
            if(S[i]=='('){
                s1.push(S[i]);
            }
            if(S[i]==')'){
                s1.pop();
            }
            temp+=S[i];
            if(s1.empty()){
                temp.erase(temp.begin());
                temp.erase(temp.end()-1);
                result+=temp;
                temp.clear();
            }
        }
        return result;
    }
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"/pkg/qct/software/llvm/release/arm/14.0.0/bin/clang" -g -Os -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -c -include AutoGen.h -mlittle-endian -fno-short-enums -save-temps -fverbose-asm -funsigned-char -ffunction-sections -fdata-sections -fno-builtin -Wno-address -fno-asynchronous-unwind-tables -target aarch64-linux-gnu -fcolor-diagnostics -fdiagnostics-format=vi -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unknown-warning-option -Wno-unused-function -Wno-bitwise-op-parentheses -mcmodel=small -ffixed-x18 -mstrict-align -fstack-protector -Wno-nonportable-include-path -Wno-misleading-indentation -fno-common -mtune=cortex-a53 -I/home/chen-docker/bin/boot/boot_images/BuildLogs/QcomPkg/SocPkg/LeMans/AU/Include -include /home/chen-docker/bin/boot/boot_images/boot/QcomPkg/Include/Library/DebugLib.h -DQCOM_EDK2_PATCH -DDISABLE_DEP -DENABLE_XN -DENABLE_ASLR -DENABLE_DEP_64 -DENABLE_EXEC_CODE_READY_TO_BOOT -DENABLE_AUTO_PLAT -DMAX_DDR_REGIONS=6 -mstrict-align -mcpu=cortex-a53 -DPRODMODE -c -o /home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/./HiiLib.obj @/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/inc.lst /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiLib/HiiLib.c /pkg/qct/software/llvm/release/arm/14.0.0/bin/clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory GNUmakefile:373: recipe for target '/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj' failed Building ... /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf [AARCH64] make: *** [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj] Error 127 make: Nothing to be done for 'tbuild'. build.py... : error 7000: Failed to execute command make tbuild [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib]错误在哪里?
最新发布
07-20

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值