算法:移除最外层的括号1021. Remove Outermost Parentheses
1021. Remove Outermost Parentheses
Input: s = "(()())(())"
Output: "()()()"
Explanation:
The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
Input: s = "(()())(())(()(()))"
Output: "()()()()(())"
Explanation:
The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".
Input: s = "()()"
Output: ""
Explanation:
The input string is "()()", with primitive decomposition "()" + "()".
After removing outer parentheses of each part, this is "" + "" = "".
超级优雅的解法,不用stack
class Solution {public String removeOuterParentheses(String s) {StringBuilder sb = new StringBuilder();int open = 0;for (char c: s.toCharArray()) {if (c == '(' && open++ > 0) sb.append(c);if (c == ')' && open-- > 1) sb.append(c);}return sb.toString();}
}
算法:移除最外层的括号1021. Remove Outermost Parentheses相关推荐
- 1021. Remove Outermost Parentheses删除最外层的括号
网址:https://leetcode.com/problems/remove-outermost-parentheses/ 使用栈的思想,选择合适的判断时机 class Solution { pub ...
- LeetCode 1021:Remove Outermost Parentheses
C语言 char * removeOuterParentheses(char * S){int len = strlen(S);int j = 0;int sum = 0;for(int i = 0; ...
- 2019年4月8日 1021. Remove Outermost Parentheses
class Solution(object):def removeOuterParentheses(self, S):""":type S: str:rtype: str ...
- 1021.删除最外层的括号
有效括号字符串为空 ("")."(" + A + ")" 或 A + B,其中 A 和 B 都是有效的括号字符串,+ 代表字符串的连接.例如 ...
- R语言dplyr包移除dataframe数据列实战(Remove Columns)
R语言dplyr包移除dataframe数据列实战(Remove Columns) 目录 R语言dplyr包移除dataframe数据列实战(Remove Columns) #导入包和仿真数据
- R语言dplyr包移除dataframe数据行实战(Remove Rows):按照条件移除数据行、按照索引移除数据行、删除包含NA值的所有数据行、删除具体列包含NA值的数据行
R语言dplyr包移除dataframe数据行实战(Remove Rows):按照条件移除数据行.按照索引移除数据行.删除包含NA值的所有数据行.删除具体列包含NA值的数据行 目录
- Bootstrap 3 移除输入框聚焦线 How to remove border (outline) around text/input boxes?
一般可以用: textarea:focus, input:focus{outline: 0; } 或者 *:focus {outline: 0; } 来源:http://stackoverflow.c ...
- leetcode题解—1021、删除最外层的括号
有效括号字符串为空 ("")."(" + A + ")" 或 A + B,其中 A 和 B 都是有效的括号字符串,+ 代表字符串的连接.例如 ...
- LeetCode 1021. 删除最外层的括号(栈)
文章目录 1. 题目 2. 解题 1. 题目 题目链接 示例 1:输入:"(()())(())" 输出:"()()()" 解释: 输入字符串为 "(( ...
- leetcode - 1021. 删除最外层的括号
有效括号字符串为空 ("")("")("")."("+A+")""(" + A ...
最新文章
- H5前端性能测试快速入门
- 【视频】React redux toolkit创建状态切片
- 大数据学习系列----大数据项目的思考
- Bootstrap3 表单帮助文本
- 使用多线程完成Socket
- 「leetcode」538.把二叉搜索树转换为累加树【递归】【迭代】详解
- 玄奥八字V5.6 爆破实例2
- 7 位 CEO 创业自述:你熬过人生中最黑暗时刻的经历,是你成为强者的必然选择...
- WebDAV之葫芦儿·派盘+Solid Explorer = 全能 Android 文件管理器
- Docker私有化部署RSSHub全记录
- 读《消费者行为心理学》-笔记
- oracle rac 成本及架构,Oracle Extended RAC 架构实战
- Elasticsearch中间隔查询slop原理
- CMakeLists.txt文件常见编译错误
- 2021Java校招笔试题答案及评分标准
- 攻防对抗形势下代码重用技术的演进
- PreTranslateMessage详解
- Tennessee Eastman(TE过程)简介
- 学习视频剪辑整理和所感
- Scrapy爬取网页并保存到数据库中
热门文章
- C#使用NPIO读写excle,并生成多个表单
- 在GridView中,设置字符超出单元格部分的内容用“...”表示
- Laravel User Agent 轻松识别客户端(微信)信息(2019版)
- RestTemplate 配置http连接池
- 【权值分块】bzoj1588 [HNOI2002]营业额统计
- Windows Phone 项目实战之我的微盘
- 云计算计算机二级,2021计算机二级office用的是哪个版本
- linux mysql 密码策略_linux密码策略
- ThinkPHP如何URL如何去掉index.php(重写模式)
- mysql post 注入工具类_【Mysql sql inject】POST方法BASE64编码注入write-up