Skip to content

Commit 589e282

Browse files
add skeleton for 1249
1 parent 5b95d10 commit 589e282

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
* 1249. Minimum Remove to Make Valid Parentheses
7+
*
8+
* Given a string s of '(' , ')' and lowercase English characters.
9+
* Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions )
10+
* so that the resulting parentheses string is valid and return any valid string.
11+
* Formally, a parentheses string is valid if and only if:
12+
* It is the empty string, contains only lowercase characters, 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+
*
16+
* Example 1:
17+
* Input: s = "lee(t(c)o)de)"
18+
* Output: "lee(t(c)o)de"
19+
* Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.
20+
*
21+
* Example 2:
22+
* Input: s = "a)b(c)d"
23+
* Output: "ab(c)d"
24+
*
25+
* Example 3:
26+
* Input: s = "))(("
27+
* Output: ""
28+
* Explanation: An empty string is also valid.
29+
*
30+
* Example 4:
31+
* Input: s = "(a(b(c)d)"
32+
* Output: "a(b(c)d)"
33+
*
34+
* Constraints:
35+
* 1 <= s.length <= 10^5
36+
* s[i] is one of '(' , ')' and lowercase English letters.
37+
* */
38+
public class _1249 {
39+
public static class Solution1 {
40+
public String minRemoveToMakeValid(String s) {
41+
//TODO: implement it
42+
return "";
43+
}
44+
}
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1249;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
public class _1249Test {
8+
private static _1249.Solution1 solution1;
9+
10+
@BeforeClass
11+
public static void setup() {
12+
solution1 = new _1249.Solution1();
13+
}
14+
15+
@Test
16+
public void test1() {
17+
System.out.println(solution1.minRemoveToMakeValid("lee(t(c)o)de)"));
18+
}
19+
20+
@Test
21+
public void test2() {
22+
System.out.println(solution1.minRemoveToMakeValid("a)b(c)d"));
23+
}
24+
25+
@Test
26+
public void test3() {
27+
System.out.println(solution1.minRemoveToMakeValid("))(("));
28+
}
29+
30+
@Test
31+
public void test4() {
32+
System.out.println(solution1.minRemoveToMakeValid("(a(b(c)d)"));
33+
}
34+
35+
@Test
36+
public void test5() {
37+
System.out.println(solution1.minRemoveToMakeValid("())()((("));//should be "()()"
38+
}
39+
40+
}

0 commit comments

Comments
 (0)