LeetCode 22. Generate Parentheses

22. Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

c++代码:

//
//  main22.cpp
//  LeetCode
//
//  Created by linSir on 2017/9/6.
//  Copyright © 2017年 58qifu. All rights reserved.
//

#include 
#include 
#include 
#include 

class Solution {
public:
    std::vector generateParenthesis(int n) {
        std::vector allComb;
        std::string comb;
        findParenthesis(n, 0, 0, comb, allComb);
        return allComb;
    }
    
    void findParenthesis(int n, int nleft, int nright, std::string &comb, std::vector &allComb) {
        if(nleft==n && nright==n) {
            allComb.push_back(comb);
            return;
        }
        
        if(nleft

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