Go语言中文网 为您找到相关结果 3

【Leetcode】:22. Generate Parentheses 问题 in Go语言

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: "((()))", "(()())", "(())()", "()(())", "()()()" 解题思路:这道题和N-Queen问题非常类似,几乎是一样的解题模式。 首先需要明白,怎么放置括号是合法的,假设n=5的情况,已经合法的放置了4个括号,那么怎么判断下一个放什么括号合法呢? 放左括号:如果之前放置的左括号数>=n,那么一定不合法 放右括号:如果之前放置的左括号数<=之前放置的右括号数,那么...阅读全文

博文 2016-05-02 23:00:00 u013564276