https://leetcode-cn.com/problems/remove-outermost-parentheses/

Java Solution

 class Solution {
public String removeOuterParentheses(String S) {
char[] chars = S.toCharArray();
int flag = 0;
StringBuilder result = new StringBuilder(); for (char c : chars) {
if (c == '(') {
if (flag == 0) {
flag ++;
continue;
}
flag ++;
} else if (c == ')') {
flag --;
if (flag == 0) {
continue;
}
}
result.append(c);
}
return result.toString();
}
}

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

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

    网址:https://leetcode.com/problems/remove-outermost-parentheses/ 使用栈的思想,选择合适的判断时机 class Solution { pub ...

  2. Leetcode 1021. Remove Outermost Parentheses

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

  3. 【Leetcode_easy】1021. Remove Outermost Parentheses

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

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

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

  5. 【leetcode】1021. Remove Outermost Parentheses

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

  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. vs code 同步

    vs code 同步需要在github上配置好gist id, 将gist id添加至setting.json中, 然后再在localsetting中设置access token,  gist id ...

  2. SCRUM REPORT DIRECTORY

    Alpha sprint scrum 1 scrum 2 scrum 3 scrum 4 scrum 5 scrum 6 scrum 7 scrum 8 scrum 9 scrum 10 Beta s ...

  3. 【知识强化】第二章 数据的表示和运算 2.4 算术逻辑单元ALU

    从本节开始我们就进入到本章的最后一节内容了,也就是我们算术逻辑单元的它的实现.这部分呢是数字电路的一些知识,所以呢,如果你没有学过数字电路的话,也不要慌张,我会从基础开始给大家补起.那么在计算机当中, ...

  4. Sql Server 出现此数据库没有有效所有者问题

    在新建数据库或附加数据库后,想添加关系表,结果出现下面的错误:  此数据库没有有效所有者,因此无法安装数据库关系图支持对象.若要继续,请首先使用“数据库属性”对话框的“文件”页或ALTER AUTHO ...

  5. 06Web服务

    1.web开发入门 1.1 引入 软件结构分类: CS结构:客户端和服务器端 特点: 1)必须安装特点的客户端程序 2)服务器端升级,客户端同步升级 BS结构:浏览器和服务器端 特点: 1)不需要安装 ...

  6. python3-返回函数

    函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回. 我们来实现一个可变参数的求和.通常情况下,求和的函数是这样定义的: def calc_sum(*args): ax = ...

  7. json和dict 在requests中请求

    上面的问题,在这么晚的夜里解决了 data 接受的是json格式数据, json 接受dict格式点的数据, 这个文章中也讲到了https://www.cnblogs.com/beile/p/1086 ...

  8. web项目分层设计

    model.dao.service.controller之间的关系,还有util和task的简介 model: 与数据库中的表一一对应,实现set和get的方法.

  9. map接口、hashmap常用方法

    注意:map中键不能重复(是否重复是根据equals方法判断),否则新的会覆盖为旧的 范例: public class TestMap { public static void main(String ...

  10. xcode7 添加个人账户 is not on any development teams

    XCODE7已经可以免费真机测试, 但添加个人账户后,显示 is not on any development teams , 解决办法: 点击 “-” 删除当前账户,退出XCODE重新打开再添加即可 ...