1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/使括号有效的最少添加 [minimum-add-to-make-parentheses-valid].html

41 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>只有满足下面几点之一,括号字符串才是有效的:</p>
<ul>
<li>它是一个空字符串,或者</li>
<li>它可以被写成&nbsp;<code>AB</code>&nbsp;<code>A</code>&nbsp;&nbsp;<code>B</code>&nbsp;连接), 其中&nbsp;<code>A</code>&nbsp;<code>B</code>&nbsp;都是有效字符串,或者</li>
<li>它可以被写作&nbsp;<code>(A)</code>,其中&nbsp;<code>A</code>&nbsp;是有效字符串。</li>
</ul>
<p>给定一个括号字符串 <code>s</code> ,在每一次操作中,你都可以在字符串的任何位置插入一个括号</p>
<ul>
<li>例如,如果 <code>s = "()))"</code> ,你可以插入一个开始括号为 <code>"(()))"</code> 或结束括号为 <code>"())))"</code></li>
</ul>
<p>返回 <em>为使结果字符串 <code>s</code> 有效而必须添加的最少括号数</em></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "())"
<strong>输出:</strong>1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "((("
<strong>输出:</strong>3
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>s</code> 只包含&nbsp;<code>'('</code>&nbsp;<code>')'</code>&nbsp;字符。</li>
</ul>