22. Generate Parentheses

class Solution {
public:
    vector generateParenthesis(int n) {
        if (n == 0)
            return res;
        dfs(0, 0, n, ""); //从左右都为0开始
        return res;
    }

    vector res;
    void dfs(int l, int r, int n, string cur) {
        if (l == n && r == n) {
            res.push_back(cur);
            return;
        }
        if (l < n)     //当左括号出现次数 

你可能感兴趣的:(22. Generate Parentheses)