|
| 1 | +<p>Given a string <font face="monospace">s</font> of <code>'('</code> , <code>')'</code> and lowercase English characters.</p> |
| 2 | + |
| 3 | +<p>Your task is to remove the minimum number of parentheses ( <code>'('</code> or <code>')'</code>, in any positions ) so that the resulting <em>parentheses string</em> is valid and return <strong>any</strong> valid string.</p> |
| 4 | + |
| 5 | +<p>Formally, a <em>parentheses string</em> is valid if and only if:</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>It is the empty string, contains only lowercase characters, or</li> |
| 9 | + <li>It can be written as <code>AB</code> (<code>A</code> concatenated with <code>B</code>), where <code>A</code> and <code>B</code> are valid strings, or</li> |
| 10 | + <li>It can be written as <code>(A)</code>, where <code>A</code> is a valid string.</li> |
| 11 | +</ul> |
| 12 | + |
| 13 | +<p> </p> |
| 14 | +<p><strong class="example">Example 1:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> s = "lee(t(c)o)de)" |
| 18 | +<strong>Output:</strong> "lee(t(c)o)de" |
| 19 | +<strong>Explanation:</strong> "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted. |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> s = "a)b(c)d" |
| 26 | +<strong>Output:</strong> "ab(c)d" |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p><strong class="example">Example 3:</strong></p> |
| 30 | + |
| 31 | +<pre> |
| 32 | +<strong>Input:</strong> s = "))((" |
| 33 | +<strong>Output:</strong> "" |
| 34 | +<strong>Explanation:</strong> An empty string is also valid. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<p><strong>Constraints:</strong></p> |
| 39 | + |
| 40 | +<ul> |
| 41 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 42 | + <li><code>s[i]</code> is either <code>'('</code> , <code>')'</code>, or lowercase English letter.</li> |
| 43 | +</ul> |
0 commit comments