LeetCode: 32. Longest Valid Parentheses

Problem: 32. Longest Valid Parentheses

Link: https://leetcode.com/problems/longest-valid-parentheses/

Difficulty: Hard

Description:

Given a string containing just the characters ‘(‘ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.

Example 1:

Input: “(()”
Output: 2
Explanation: The longest valid parentheses substring is “()”

Example 2:

Input: “)()())”
Output: 4
Explanation: The longest valid parentheses substring is “()()”

Solution: 

Language: Swift

Runtime: 24ms
Memory: 20.0MB

Copy to Clipboard