1078. Remove Outermost Parentheses
My accepted C++ solution to LeetCode problem 1078, Remove Outermost Parentheses, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 8.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 8.9MB, accepted 2025-12-27.
class Solution {
public:
string removeOuterParentheses(string s) {
string res;
int depth = 0;
for (char c : s) {
if (c == '(' && depth++ > 0) res += c;
if (c == ')' && --depth > 0) res += c;
}
return res;
}
};