标签:lis leetcode style parent turn backtrac gen backtrack oid
backtracking
class Solution { public List<String> generateParenthesis(int n) { List<String> list=new ArrayList<>(); if(n==0) return list; generate(list, "", n, 0, 0); return list; } public void generate(List<String> list, String str, int n, int nleft, int index){ if(index>=2*n){ list.add(str);return; } if(nleft<n){ generate(list, str+‘(‘, n, nleft+1, index+1); } if(index-nleft<nleft){ generate(list, str+‘)‘, n, nleft, index+1); } } }
leetcode 22-Generate Parentheses(medium)
标签:lis leetcode style parent turn backtrac gen backtrack oid
原文地址:https://www.cnblogs.com/yshi12/p/9690142.html