代码如下: 1classSolution {2public:3voidgenerate(intleft,intright,strings, vector<string>&ret) {4//左侧剩余括号比右侧剩余要多5if(right <left)6return;78//左侧与右侧无剩余9if(!left && !right) {10ret.push_back(s);11return;12}1314//加一个左侧括号,左侧剩余括号少1个15if(left >0) {16...
蜗牛慢慢爬 LeetCode 22. Generate Parentheses [Difficulty: Medium]题目 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ "((()))", "(()())", "(())()", "()(())", "()()(...
My Solutions to Leetcode problems. All solutions support C++ language, some support Java and Python. Multiple solutions will be given by most problems. Enjoy:) 我的Leetcode解答。所有的问题都支持C++语言,一部分问题支持Java语言。近乎所有问题都会提供多个算