|
1 | 1 | packagecom.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -importjava.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 | 3 | publicclass_1249 {
|
39 | 4 | publicstaticclassSolution1 {
|
40 | 5 | publicStringminRemoveToMakeValid(Strings) {
|
|