编程语言
首页 > 编程语言> > LeetCode-1021 Remove Outermost Parentheses Solution(with Java)

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 }

 

标签:Parentheses,1021,opened,Outermost,Solution,&&,StringBuilder,append,Strin
来源: https://www.cnblogs.com/sheepcore/p/12396547.html