一:题目
二:上码
class Solution {public List<String> generateParenthesis(int n) {List<String> ans = new ArrayList<>();def(ans,new StringBuilder(),n,n);return ans;}public void def(List<String> ans,StringBuilder path,int left,int right) {if (left == 0 && right == 0) {ans.add(path.toString());return ;}if (right < left) return ;if (left > 0) {path.append("(");def(ans,path,left-1,right);path.deleteCharAt(path.length()-1);}if (right > 0) {path.append(")");def(ans,path,left,right-1);path.deleteCharAt(path.length()-1);}}}