|
-- Posted by matto at 8:04 pm on Nov. 12, 2008
So I'm doing this problem, and I've entered the code: | Code: | public int strDist(String str, String sub) { if( str.length()==0 ) return 0; if( !(str.substring(0, sub.length()).equals(sub)) ) { return strDist( str.substring(1, str.length()), sub); } if( !( str.substring( str.length()-sub.length(), str.length()).equals(sub) ) ) { return strDist( str.substring(0, str.length()-1), sub); } return str.length(); } | And it passes all the tests except "other tests," which isn't useful since I don't know what's causing it to break. Any ideas? This is not kewl. :(
-- Posted by glowinthedark at 8:06 pm on Nov. 12, 2008
i thought this was about coffee.. dang it!
-- Posted by bratalvarado at 8:08 pm on Nov. 12, 2008
wait what is this about
-- Posted by Majo at 8:09 pm on Nov. 12, 2008
I wish I understood that but Java I kicked my ass, sorry.
-- Posted by h a t t at 8:30 pm on Nov. 12, 2008
well i ran it in eclipse and it got the results it was looking for so i don't know what the X is about.
-- Posted by matto at 8:32 pm on Nov. 12, 2008
yawtf. I'm trying to come up with a situation that'd cause it to fail... can't think of anything.
-- Posted by h a t t at 8:35 pm on Nov. 12, 2008
ah. it fails if the string doesn't contain the other string anywhere.
-- Posted by h a t t at 8:40 pm on Nov. 12, 2008
just added if (str.indexOf(sub) == -1 ) return 0; to the top and it works (when the index is -1 it means that the string is nowhere to be found)
-- Posted by matto at 8:49 pm on Nov. 12, 2008
o snap alright. thanks. that's a useful method....
|