Generate Parentheses Algorithm

Specific forms of the mark include rounded brackets (also named parenthesis), square brackets, curly brackets (also named braces), and angle brackets (also named chevrons), as well as various less common pairs of symbols. typically deployed in symmetric pairs, an individual bracket may be identify as a left or right bracket or, alternatively, an opening paired bracket or closing paired bracket, respectively, depending on the directionality of the context. Chevrons, ⟨ ⟩, were the earliest type of bracket to look in write English. Desiderius Erasmus coined the term lunula to refer to the rounded parenthesis, (), recalling the shape of the crescent moon.
class Solution {
public:
    vector<string> generateParenthesis(int n) {
        vector<string> result;
        string s;
        if (n == 0) {
            return result;
        }
        dfs(result, s, n, n);
        return result;
    }
    void dfs(vector<string>& result, string& s, int left, int right) {
        if (left > right) {
            return;
        }
        if (left == 0 && right == 0) {
            result.push_back(s);
            return;
        }
        if (left >= 1) {
            s.push_back('(');
            dfs(result, s, left - 1, right);
            s.pop_back();
        }
        if (right >= 1) {
            s.push_back(')');
            dfs(result, s, left, right - 1);
            s.pop_back();
        }
    }
};

LANGUAGE:

DARK MODE: