java.lang.Object
g0001_0100.s0032_longest_valid_parentheses.Solution

public class Solution extends Object
32 - Longest Valid Parentheses.<p>Hard</p> <p>Given a string containing just the characters <code>'('</code> and <code>')'</code>, find the length of the longest valid (well-formed) parentheses substring.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;(()&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The longest valid parentheses substring is &ldquo;()&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;)()())&rdquo;</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The longest valid parentheses substring is &ldquo;()()&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &quot;&quot;</p> <p><strong>Output:</strong> 0</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= s.length <= 3 * 10<sup>4</sup></code></li> <li><code>s[i]</code> is <code>'('</code>, or <code>')'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • longestValidParentheses

      public int longestValidParentheses(String s)