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


Runtime: 66 ms, faster than 54.59% of Python3 online submissions for Longest Valid Parentheses.

Memory Usage: 14.7 MB, less than 24.31% of Python3 online submissions for Longest Valid Parentheses.


```python
class Solution:
    def longestValidParentheses(self, s: str) -> int:
        #08:45 start to check the question, and realize I don't know how to answer it, so I did a check on the discuss part
        #08:54
        memory = [-1]
        max_length = 0
        for index, char in enumerate(s):
            if (char == "("):
                memory.append(index)
            else:
                memory.pop()
                if (len(memory) == 0):
                    memory.append(index)
                else:
                    max_length = max(max_length, index - memory[-1])
        return max_length
        #8:56
```
