相关知识 http://blog.csdn.net/wuzhekai1985/article/details/6764858
public class Solution {
public ArrayList<String> generateParenthesis(int n) {//ref http://blog.csdn.net/linhuanmars/article/details/19873463
ArrayList<String> res = new ArrayList<String>();
if(n<1) return res;
dfs(n,n,new String(), res);
return res;
}
public void dfs(int nl, int nr, String item, ArrayList<String> res){
if(nl>nr) return;
if(nl==0 && nr ==0) res.add(item);
if(nl>0){
dfs(nl-1,nr,item+'(',res);
}
if(nr>0){
dfs(nl,nr-1,item+')',res);
}
}
}