How to return all valid combinations of n-pairs of parentheses?
问题 def paren(n): lst = ['(' for x in range(n)] current_string = ''.join(lst) solutions = list() for i in range(len(current_string)+1): close(current_string, n, i, solutions) return solutions def close(current_string, num_close_parens, index, solutions): """close parentheses recursively""" if num_close_parens == 0: if current_string not in solutions: solutions.append(current_string) return new_str = current_string[:index] + ')' + current_string[index:] if num_close_parens and is_valid(new_str[