0
Help, there is a case that my code is wrong in C++
Is about the function isPalindrome. I thing this working well in integer positive and zero, but not pass a hidden testing in the course project. https://code.sololearn.com/c1Do5jXLTDK6/?ref=app.
6 Answers
+ 2
Ipang yes, I'm maybe over-complicating for this, but it was first thing that ocurred to me.
+ 1
Seems to me you're over-complicating it. Use the common way to reverse a number using division and modulo, then compare original number with its reversed version. If they were similar, the original number is a palindrome number.
+ 1
I understand negative numbers are not palindromic, and the code seems to get this correctly.
It probably is failing some edge case I can't identify. I'd check if the log10 always returns as expected for ints.
+ 1
It starts failing at 9999999
0
Emerson Prado wow, you're right. For n>=9999999 returns is Not a palindrome. Why is this?
0
Daniel DĂĄvalos Probably some rouding issue. It works for higher numbers, but only with lots of 9's.