30:00
Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring.
0≤s.length≤3×1040 \leq s.\text{length} \leq 3 \times 10^40≤s.length≤3×104
s[i] is '(' or ')'.
s[i]
'('
')'
Initialize stack with -1 as base index
(
0
1
)
2
Stack (indices)
-1
Index:
Max Length:
Current
Valid
In Stack