LeetCode 1021. Remove Outermost Parentheses

Problem Statement


impl Solution {
pub fn remove_outer_parentheses(s: String) -> String {
let (mut ans, mut open) = ("".to_string(), 0);
for c in s.chars() {
if c == '(' {
if open > 0 {
ans.push(c);
}
open += 1;
}
if c == ')'{
if open > 1 {
ans.push(c);
}
open -= 1;
}
}
return ans;
}
}