网址:https://leetcode.com/problems/remove-outermost-parentheses/

使用栈的思想,选择合适的判断时机

class Solution {
public:
string removeOuterParentheses(string S)
{
stack<char> s_ch;
string ans;
stack<char> temp;
int l = , r = ;
for(int i = ; i<S.size(); i++)
{
if(S[i] == '(')
{
s_ch.push(S[i]);
l++;
}
else
{
r++;
if(s_ch.size() % == && r==l)
{
ans = ans + S.substr(i+-s_ch.size(), s_ch.size()-);
s_ch = temp;
l = ; r = ;
}
else
s_ch.push(S[i]);
}
}
return ans;
}
};

删除最外层的括号

1021. Remove Outermost Parentheses删除最外层的括号的更多相关文章

  1. LeetCode #1021. Remove Outermost Parentheses 删除最外层的括号

    https://leetcode-cn.com/problems/remove-outermost-parentheses/ Java Solution class Solution { public ...

  2. 【Leetcode_easy】1021. Remove Outermost Parentheses

    problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完

  3. 【LeetCode】1021. Remove Outermost Parentheses 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcod ...

  4. 【leetcode】1021. Remove Outermost Parentheses

    题目如下: A valid parentheses string is either empty (""), "(" + A + ")", ...

  5. Leetcode 1021. Remove Outermost Parentheses

    括号匹配想到用栈来做: class Solution: def removeOuterParentheses(self, S: str) -> str: size=len(S) if size= ...

  6. LeetCode 1021. 删除最外层的括号(Remove Outermost Parentheses)

    1021. 删除最外层的括号 1021. Remove Outermost Parentheses 题目描述 有效括号字符串为空 ("")."(" + A + ...

  7. LeetCode--To Lower Case && Remove Outermost Parentheses (Easy)

    709. To Lower Case(Easy)# Implement function ToLowerCase() that has a string parameter str, and retu ...

  8. Leetcode 5016. 删除最外层的括号

    5016. 删除最外层的括号  显示英文描述 我的提交返回竞赛   用户通过次数446 用户尝试次数469 通过次数456 提交次数577 题目难度Easy 有效括号字符串为空 ("&quo ...

  9. [Swift]LeetCode1021. 删除最外层的括号 | Remove Outermost Parentheses

    A valid parentheses string is either empty (""), "(" + A + ")", or A + ...

随机推荐

  1. java框架之Spring(2)-注解配置IOC&AOP配置

    注解配置IoC 准备 1.要使用注解方式配置 IoC,除了之前引入的基础 jar 包,还需要引入 spring-aop 支持包,如下: 2.在 applicationContext.xml 中引入 c ...

  2. vs安装问题

    1 首先windows update异常,导致vs2015的一个安装不上,先试着修一下: https://support.microsoft.com/zh-cn/help/2629484 如果提示:“ ...

  3. FastDFS的单点部署

    1  安装libfastcommon 注意:在Centos7下和在Ubuntu下安装FastDFS是不同的,在Ubuntu上安装FastDFS需要安装libevent,而外Centos上安装FastD ...

  4. Vue系列之 => webpack基础使用

    webpack安装方式 1,运行 npm i webpack -g 全局安装. 2,在项目根目录中运行 npm i webpack --save-dev 安装到项目依赖中 项目目录 进入src运行, ...

  5. 关闭jtag保留swd

    串行线JTAG 配置 (Serial wire JTAG configuration)  位26:24  这些位只能由软件写( 读这些位,将返回未定义的数值) ,用于配置SWJ和跟踪复用功能的I/O ...

  6. [openjudge-贪心]删数问题

    题目描述 题目描述 键盘输入一个高精度的正整数N,去掉其中任意k个数字后剩下的数字按原左右次序将组成一个新的正整数.编程对给定的N和k,寻找一种方案使得剩下的数字组成的新数最小. 输出应包括所去掉的数 ...

  7. Python多线程threading的使用

    一. threading的参数传递,参数之后的’,‘不能少,此处的’,‘是用来区分此参数作为元组(包含多个参数)来传递的,而不是单个参数传递 #coding:utf- import threading ...

  8. P1996 约瑟夫问题

    P1996 约瑟夫问题 广度优先搜索 我竟然寄几做对了 这个题用到了队列 下面详细解释: 我的代码: #include<iostream> #include<cstdio> # ...

  9. [c/c++] programming之路(15)、多维数组和二分查找法,小外挂

    一.多维数组 #include<stdio.h> #include<stdlib.h> void main(){ ][]; int i,j; ; i < ; i++) { ...

  10. python from entry to abandon3

    第十章的内容是解决问题————编写一个Python脚本.在我的电脑上因为Zip命令不能正常工作所以无法给出演示.该章给出了很有意义的编程思路,对以后学习和工作都有不错的参考意义,这部分有兴趣的同学还是 ...