我试图从Java中的字符串一次删除字符这是我写的
String word = "evelina";
char[] wordCharArr = word.toCharArray();
//Deleting one
for(int i = 0; i< wordCharArr.length; i++)
{
String answer = word.subString(i);
if(list.lookup(answer))
perm.add(answer);
}
这是做什么的:
evelina
velina
elina
lina
ina
na
a
但我需要它来做这个
evelina
velina
eelina
evlina
eveina
evelna
evelia
evelin
答案 0 :(得分:3)
在每次迭代时,您需要跳过i-th
字符:
for (int i = 0; i < wordCharArr.length; i++) {
String answer = word.substring(0, i) + word.substring(i + 1);
if (list.lookup(answer)) {
perm.add(answer);
}
}