MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / remove_outer_parentheses

Function remove_outer_parentheses

1021-remove-outermost-parentheses.rs:5–20  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

3// 妙啊
4
5pub fn remove_outer_parentheses(s: String) -> String {
6 let mut level = 0;
7 let mut ret = String::new();
8 for c in s.chars() {
9 if c == ')' {
10 level -= 1;
11 }
12 if level >= 1 {
13 ret.push(c);
14 }
15 if c == '(' {
16 level += 1;
17 }
18 }
19 ret
20}
21
22fn main() {
23 let s = "(()())(())".to_string();

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected