Dictionary Word 1
public boolean canBreak(String input, String[] dict){
boolean[] m = new boolean[input.length() + 1];
m[0] = true;
Set<String> dictionary = new HashSet<>(Arrays.asList(dict));
for (int i = 1; i <= m.length; i++){ //check every increment
for (int j = 0; j < i; j++){ //check every cut of every increment
if (m[j] && dictionary.contains(input.substring(j, i))){
m[j] = true;
break;
}
}
}
return m[m.length - 1];
} Last updated