public class Solution { public void unguarded_generate(List<String> result,String curr,int m,int n){ if(m==0&&n==0){ result.add(curr); } else { if(m!=0){ unguarded_generate(result,curr+"(",m-1,n); } if(m<n&&n!=0){ unguarded_generate(result,curr+")",m,n-1); } } } public List<String> generateParenthesis(int n) { List<String> result=new ArrayList<String>(); if(n>0){ unguarded_generate(result,new String(),n,n); } return result; } }
LeetCode---Generate Parentheses
原文:http://blog.csdn.net/ivyvae/article/details/41081497