File tree 1 file changed +0
-32
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +0
-32
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .util .Stack ;
4
4
5
- /**
6
- * 921. Minimum Add to Make Parentheses Valid
7
- *
8
- * Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', and in any positions )
9
- * so that the resulting parentheses string is valid.
10
- *
11
- * Formally, a parentheses string is valid if and only if:
12
- * It is the empty string, or
13
- * It can be written as AB (A concatenated with B), where A and B are valid strings, or
14
- * It can be written as (A), where A is a valid string.
15
- * Given a parentheses string, return the minimum number of parentheses we must add to make the resulting string valid.
16
- *
17
- * Example 1:
18
- * Input: "())"
19
- * Output: 1
20
- *
21
- * Example 2:
22
- * Input: "((("
23
- * Output: 3
24
- *
25
- * Example 3:
26
- * Input: "()"
27
- * Output: 0
28
- *
29
- * Example 4:
30
- * Input: "()))(("
31
- * Output: 4
32
- *
33
- * Note:
34
- * S.length <= 1000
35
- * S only consists of '(' and ')' characters.
36
- * */
37
5
public class _921 {
38
6
public static class Solution1 {
39
7
public int minAddToMakeValid (String S ) {
You can’t perform that action at this time.
0 commit comments