java.lang.Object
g1201_1300.s1249_minimum_remove_to_make_valid_parentheses.Solution

public class Solution extends Object
1249 - Minimum Remove to Make Valid Parentheses.<p>Medium</p> <p>Given a string s of <code>'('</code> , <code>')'</code> and lowercase English characters.</p> <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> <p>Formally, a <em>parentheses string</em> is valid if and only if:</p> <ul> <li>It is the empty string, contains only lowercase characters, or</li> <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> <li>It can be written as <code>(A)</code>, where <code>A</code> is a valid string.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;lee(t(c)o)de)&rdquo;</p> <p><strong>Output:</strong> &ldquo;lee(t(c)o)de&rdquo;</p> <p><strong>Explanation:</strong> &ldquo;lee(t(co)de)&rdquo; , &ldquo;lee(t(c)ode)&rdquo; would also be accepted.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;a)b(c)d&rdquo;</p> <p><strong>Output:</strong> &ldquo;ab(c)d&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;))((&rdquo;</p> <p><strong>Output:</strong> &quot;&quot;</p> <p><strong>Explanation:</strong> An empty string is also valid.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s[i]</code> is either<code>'('</code> , <code>')'</code>, or lowercase English letter<code>.</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minRemoveToMakeValid

      public String minRemoveToMakeValid(String s)