LeetCode算法题——生成有效括号组合

题目

给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。
例如,给出 n = 3,生成结果为:
[
  "((()))",
  "(()())",
  "(())()",
  "()(())",
  "()()()"
]

 

代码实现

public class day {
	
	public static void main(String[] args) {
	
		int max = 1;
		int n = 3;
		int digit = n*2;
		ArrayList arr = new ArrayList<>();
		
		for(int i=0;i end_list = new ArrayList<>();
		for(int i=0;i0) {
						break;
					}
				}else{
					end = end +1;
					if(end>0) {
						break;
					}
				}
				if(j==temp.length()-1&&end>=0) {
					end_list.add(temp);
				}
			}
		}
		
		ArrayList over = new ArrayList<>();
		
		for(int i=0;i

 

你可能感兴趣的:(算法)