LeetCode solutions

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

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 8.9MB, accepted 2025-12-27.

cpp
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;
    }
};

Source