50,526
社区成员
发帖
与我相关
我的任务
分享
public List<String> findLessThenLength(int length){
for(int i=2; i<=length; i++){
this.findAtLength(i);
}
return all;
}
public void findAtLength(int length){
find(start, 0, length);
}
public void find(String s, int i, int n) {
// 保存上一次的字符串
String temp = s;
// 判断是否符合要求
if (s.length() == n) {
// 过滤:1.相邻的字母不重复
if(isValid(s)){
result.add(StringHelper.convertRouteWithIndex(s));
}
return;
}
// 从寻找点开始循环
// 减少寻址范围
String tempLast = temp.substring(temp.length() - 1);
String tempSeed = neighborMap.get(tempLast);
for (int k = i; k < tempSeed.length(); k++) {
s = temp;
s += tempSeed.charAt(k);
find(s, 0, n);
}
}