Mohan
BAN USERWe have 2 use cases when a word matches
1.Either the next word starts from the next char
2.The word is part of a bigger word hence continue to check
some examples - timesofindia - we should match times of india
timesoftindia - time soft india.
Code below returns boolean of whether all words are part of dictionary
public static boolean validDictionarywords(String s, int startIndex, int endIndex){
boolean status = false;
for(int end = startIndex+1,start=startIndex ; end <= endIndex; end++){
if( isValidDictionaryword(s.substring(start, end))){
if(end == endIndex){
return true;
}
String newString = s.substring(end, endIndex);
status = validDictionarywords(newString, 0,newString.length() );
if(status){
return true;
}
}
}
return status;
}
This will the correctness of the code - For example if u r using Hashmap it uses equals and hashcode if u override one and not the other then Hashmap will be inconsistent.
- Mohan February 18, 2013