Given a string containing just the characters '('
and ')'
,
find the length of the longest valid (well-formed) parentheses substring.
For "(()"
, the longest valid parentheses
substring is "()"
, which has length = 2.
Another example is ")()())"
, where the longest
valid parentheses substring is "()()"
, which has length = 4.
Subscribe to see which companies asked this question
思路:
使用stack來保存未匹配的“括號”的下標,然后求下標之間的最大差值。
c++ code:
上一篇 第三章 網絡體系結構