: , , , , , .
:
-, :
private static boolean recur(String word, int length) {
while(true) {
if(length == 1 || length == 2)
return false;
if(length == 0)
return true;
if(words[length].contains(word.substring(0, length))) {
int newlen = word.length() - length;
word = word.substring(length);
length = newlen;
}
else {
--length;
}
}
}
, .
, , !
( , , , - .)
, ABCDEFGH, ABCD, EFGH ABCDE - , FGH - . recur , ABCDE, , FGH , ABCDEFGH .
ABCD EFGH! , , . ( , , ABC , DEFGH - .)
:
private static boolean recur(String word, int length) {
if(length == 1 || length == 2)
return false;
if(length == 0)
return true;
return (words[length].contains(word.substring(0, length)))
&& recur(word.substring(length), word.length() - length))
|| recur(word, length-1);
}
: . , , . , .