LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

1. Description:

Notes:

2. Examples:

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 }
原文地址:https://www.cnblogs.com/sheepcore/p/12396547.html