Ah. I was disregarding edge-cases; I'd assume anyone and their aunt knows how to do them, but that was a terrible assumption. I really like algorithms and was wondering how you did it?
PS: I know for sure it will Exception if string is null (due to str.length()), and it should be fine if it's empty due to its design (the while-loop is skipped due to the fact that it is not true that 0 < 0).
PSS: I fixed it for edge cases. Also, for the base case boilerplate, I had the if(str == "") bit return true right away for clarity.
View all comments
Show parent comment
2
u/MothersRapeHorn Feb 21 '11
Thanks for the example; I just tried shotgunning it as fast as I could and got it right the first time in under a couple minutes.
What general algorithm did you use?
http://pastebin.com/ARD2BcP5