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:
"((()))", "(()())", "(())()", "()(())", "()()()"
public class Solution { private ArrayListrel= new ArrayList (); public ArrayList generateParenthesis(int n) { // Start typing your Java solution below // DO NOT write main() function rel.clear(); char[] arr = new char[2*n]; genCur(2*n,n,0,0, arr); return rel; } private void genCur(int sz, int left, int right, int level, char[] arr) { if(level == sz) { rel.add( new String(arr) ); return; } if(left>0) { arr[level] = '('; genCur(sz,left-1, right+1, level+1, arr); } if(right>0) { arr[level] = ')'; genCur(sz,left, right-1, level+1, arr); } }}