LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

1. Description:

LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

Notes:

LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

2. Examples:

LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

3.Solutions: 

 1 /**
 2  * Created by sheepcore on 2018-12-24
 3  */
 4 class Solution {
 5        public String removeOuterParentheses(String S) {
 6         StringBuilder s = new StringBuilder();
 7         int opened = 0;
 8         for (char c : S.toCharArray()) {
 9             if (c == '(' && opened++ > 0) s.append(c);
10             if (c == ')' && opened-- > 1) s.append(c);
11         }
12         return s.toString();
13     }
14 }

 

上一篇:Java正则表达式从字符串中删除重复的子字符串


下一篇:python – Pandas DataFrame计算重复行并填充列