1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 08:55:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/最长有效括号 [longest-valid-parentheses].html
2025-09-29 14:46:20 +08:00

42 lines
1.0 KiB
HTML
Raw Permalink 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>给你一个只包含 <code>'('</code><code>')'</code> 的字符串,找出最长有效(格式正确且连续)括号 <span data-keyword="substring">子串</span> 的长度。</p>
<p>左右括号匹配,即每个左括号都有对应的右括号将其闭合的字符串是格式正确的,比如&nbsp;<code>"(()())"</code></p>
<p>&nbsp;</p>
<div class="original__bRMd">
<div>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "(()"
<strong>输出:</strong>2
<strong>解释:</strong>最长有效括号子串是 "()"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = ")()())"
<strong>输出:</strong>4
<strong>解释:</strong>最长有效括号子串是 "()()"
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = ""
<strong>输出:</strong>0
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= s.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>s[i]</code><code>'('</code><code>')'</code></li>
</ul>
</div>
</div>