67,512
社区成员
发帖
与我相关
我的任务
分享
public List<String> perm(List<String> list, int number) {
if (number == 1) {
return list;
}
Set<String> set = new HashSet<String>();
List<String> results = new ArrayList<String>();
for (String str : list) {
if (!set.contains(str)) {
set.add(str);
List<String> subResults = perm(list, number - 1);
for (String subResult : subResults) {
results.add(str + subResult);
}
}
}
return results;
}