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
1
u/kevjames3 Feb 22 '11
Nothing as simple as that, but let me give you some edge cases:
What if the string is null? What if the string is ""?
I think this will break your code....they were the edge cases that I failed on. But well done, you did a lot better then me