32. Longest Valid Parentheses Hard

@problem@discussion
#String#Dynamic Programming#Stack



1/**
2 * [32] Longest Valid Parentheses
3 *
4 * Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
5 *  
6 * Example 1:
7 * 
8 * Input: s = "(()"
9 * Output: 2
10 * Explanation: The longest valid parentheses substring is "()".
11 * 
12 * Example 2:
13 * 
14 * Input: s = ")()())"
15 * Output: 4
16 * Explanation: The longest valid parentheses substring is "()()".
17 * 
18 * Example 3:
19 * 
20 * Input: s = ""
21 * Output: 0
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	0 <= s.length <= 3 * 10^4
27 * 	s[i] is '(', or ')'.
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/longest-valid-parentheses/
33// discuss: https://leetcode.com/problems/longest-valid-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn longest_valid_parentheses(s: String) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_32() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.