1021. Remove Outermost Parentheses Easy
1/**
2 * [1021] Remove Outermost Parentheses
3 *
4 * A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.
5 *
6 * For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
7 *
8 * A valid parentheses string s is primitive if it is nonempty, and there does not exist a way to split it into s = A + B, with A and B nonempty valid parentheses strings.
9 * Given a valid parentheses string s, consider its primitive decomposition: s = P1 + P2 + ... + Pk, where Pi are primitive valid parentheses strings.
10 * Return s after removing the outermost parentheses of every primitive string in the primitive decomposition of s.
11 *
12 * Example 1:
13 *
14 * Input: s = "(()())(())"
15 * Output: "()()()"
16 * Explanation:
17 * The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
18 * After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
19 *
20 * Example 2:
21 *
22 * Input: s = "(()())(())(()(()))"
23 * Output: "()()()()(())"
24 * Explanation:
25 * The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
26 * After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".
27 *
28 * Example 3:
29 *
30 * Input: s = "()()"
31 * Output: ""
32 * Explanation:
33 * The input string is "()()", with primitive decomposition "()" + "()".
34 * After removing outer parentheses of each part, this is "" + "" = "".
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= s.length <= 10^5
40 * s[i] is either '(' or ')'.
41 * s is a valid parentheses string.
42 *
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/remove-outermost-parentheses/
47// discuss: https://leetcode.com/problems/remove-outermost-parentheses/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52 pub fn remove_outer_parentheses(s: String) -> String {
53 String::new()
54 }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_1021() {
65 }
66}
67
Back
© 2025 bowen.ge All Rights Reserved.