[leetcode]22. Generate Parentheses
2017-01-18 17:34
459 查看
题目链接:https://leetcode.com/problems/generate-parentheses/
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:
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:
[ "((()))", "(()())", "(())()", "()(())", "()()()" ]
class Solution{ public: vector<string> generateParenthesis(int n) { vector<string> result; combination(result,"",n,n); return result; } void combination(vector<string> &result,string com,int left,int right) { if(left>right) { return; } if(left==0 && right==0) { result.push_back(com); return; } if(left>0) combination(result,com+"(",left-1,right); if(right>0) combination(result,com+")",left,right-1); } };
相关文章推荐
- LeetCode - 22. Generate Parentheses
- leetcode 22. Generate Parentheses 巧妙的递归形式
- python写算法题:leetcode: 22. Generate Parentheses
- Leetcode 22. Generate Parentheses
- leetcode-java-22. Generate Parentheses
- LeetCode 22. Generate Parentheses 题解 —— Java
- DFS leetcode 22. Generate Parentheses
- leetcode:22. Generate Parentheses
- LeetCode22. Generate Parentheses
- LeetCode 22. Generate Parentheses 解题报告
- LeetCode-22. Generate Parentheses
- Leetcode22. Generate Parentheses
- [LeetCode]22. Generate Parentheses
- LeetCode 22. Generate Parentheses
- leetcode_22. Generate Parentheses 生成括号,给n对括号,有多少种括号生成方式
- 【leetcode】22. Generate Parentheses
- 【LeetCode】22. Generate Parentheses 解题报告
- LeetCodet题解--22. Generate Parentheses(生成n对匹配的括号)
- [leetcode]22. Generate Parentheses
- leetcode 20|22|32. Valid Parentheses 22. Generate Parentheses 32. Longest Valid Parentheses