921. Minimum Add to Make Parentheses Valid Medium

@problem@discussion
#String#Stack#Greedy



1/**
2 * [921] Minimum Add to Make Parentheses Valid
3 *
4 * A parentheses string is valid if and only if:
5 * 
6 * 	It is the empty string,
7 * 	It can be written as AB (A concatenated with B), where A and B are valid strings, or
8 * 	It can be written as (A), where A is a valid string.
9 * 
10 * You are given a parentheses string s. In one move, you can insert a parenthesis at any position of the string.
11 * 
12 * 	For example, if s = "()))", you can insert an opening parenthesis to be "(()))" or a closing parenthesis to be "())))".
13 * 
14 * Return the minimum number of moves required to make s valid.
15 *  
16 * Example 1:
17 * 
18 * Input: s = "())"
19 * Output: 1
20 * 
21 * Example 2:
22 * 
23 * Input: s = "((("
24 * Output: 3
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= s.length <= 1000
30 * 	s[i] is either '(' or ')'.
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/
36// discuss: https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn min_add_to_make_valid(s: String) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_921() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.