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. MySQL语句之数据的增删改查

    1.插入记录insert语法:INSERT INTO tablename (field1,field2,……fieldn) VALUES(value1,value2,……valuesn); 也可以一次 ...

  2. C#/.NET VS2017+ EF+SQLite.CodeFirst——真正实现CodeFirst

    本文所介绍的是真正的EF+CodeFirst,不需要提前建表,由代码自动生成! 进行前需要准备的: 1.下载Sqlite Experthttp://www.sqliteexpert.com/downl ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C

    题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...

  4. css3-css3属性选择器

    在HTML中,通过各种各样的属性可以给元素增加很多附加的信息.例如,通过id属性可以将不同div元素进行区分. 在CSS2中引入了一些属性选择器,而CSS3在CSS2的基础上对属性选择器进行了扩展,新 ...

  5. bzoj4771 七彩树 dfs序+主席树+树链的并

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4771 题解 一道不错的树链并的基础练习题. 如果不是树,而是一个数组的话,对于给定区间内的不同 ...

  6. kafka 磁盘写满导致 InternalError

    tailf kafka/log/server.log [2019-12-19 17:19:05,121] FATAL (main kafka.server.KafkaServerStartable 1 ...

  7. Check the port occupy on Mac OSX

    Check the port occupy on Mac OSX lsof -i :7070 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME si ...

  8. Python3解leetcode Reach a Number

    问题描述: You are standing at position 0 on an infinite number line. There is a goal at position target. ...

  9. nodejs通过async/await来操作MySQL

    在nodejs中从数据库得到数据后是通过回调函数来操作数据的,如果嵌套多层将非常可怕,代码逻辑和可读性将变得非常差.有时用promise也并不能很好得解决问题,因为如果用了promise后,代码将会有 ...

  10. ubuntu18.04-安装最新cmake

    https://www.linuxidc.com/Linux/2018-09/154165.htm