Question
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
Example 1:
Input: s = "(()" Output: 2 Explanation: The longest valid parentheses substring is "()".
Example 2:
Input: s = ")()())" Output: 4 Explanation: The longest valid parentheses substring is "()()".
Example 3:
Input: s = "" Output: 0
Constraints:
0 <= s.length <= 3 * 104s[i]is'(', or')'.
Python Solution
class Solution:
def longestValidParentheses(self, s: str) -> int:
stack = [-1]
max_len = 0
for p in range(len(s)):
if s[p] == '(':
stack.append(p)
else:
stack.pop()
if stack == []:
stack.append(p)
else:
max_len = max(p-stack[-1],max_len)
return(max_len)

![[Solved] You are given an integer n and an integer start. Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums.](https://machinelearningprojects.net/wp-content/uploads/2022/09/Leetcode-solutions-MLP-Feature-Image-1024x536.webp)