Monday, October 6, 2014

Generate Parentheses

Problem

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:
"((()))", "(()())", "(())()", "()(())", "()()()"

Idea

dfs暴力搜索,解的长度为2n,当找到2n长的一个solution后判断其是否valid

Solution


No comments:

Post a Comment