1249. Minimum Remove to Make Valid Parentheses Medium
1/**
2 * [1249] Minimum Remove to Make Valid Parentheses
3 *
4 * Given a string <font face="monospace">s</font> of '(' , ')' and lowercase English characters.
5 * Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.
6 * Formally, a parentheses string is valid if and only if:
7 *
8 * It is the empty string, contains only lowercase characters, or
9 * It can be written as AB (A concatenated with B), where A and B are valid strings, or
10 * It can be written as (A), where A is a valid string.
11 *
12 *
13 * Example 1:
14 *
15 * Input: s = "lee(t(c)o)de)"
16 * Output: "lee(t(c)o)de"
17 * Explanation: "lee(t(co)de)" , "lee(t(c)ode)" would also be accepted.
18 *
19 * Example 2:
20 *
21 * Input: s = "a)b(c)d"
22 * Output: "ab(c)d"
23 *
24 * Example 3:
25 *
26 * Input: s = "))(("
27 * Output: ""
28 * Explanation: An empty string is also valid.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= s.length <= 10^5
34 * s[i] is either'(' , ')', or lowercase English letter.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/
40// discuss: https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn min_remove_to_make_valid(s: String) -> String {
46 String::new()
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_1249() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.