-2147447412 is not a palindromic number

  • 87

    I am wondering how the other people got their code ACed, the testing result of "-2147447412" seems a little odd to me. Should it be a palindromic number or not?

    Note: I believe the range of int is [-2147483648, 2147483647] and "-2147447412" is not overflowed, plus I handled the overflow cases already (test case "-2147483648" in particular).

    11499 / 11502 test cases passed.

    Status: Wrong Answer

    Input: -2147447412

    Output: true

    Expected: false

    Here's my second question:

    Why does the function take "int" as input instead of "unsigned int", when we assume all negative numbers are NOT palindromic.

  • 8

    Well, it seems the definition of "a palindromic number" for this OJ problem is that all negative numbers should return false.
    I deleted the code that handles the inverse of -2147483648 (overflow), simply returns false for all negative numbers.
    Problem solved.

    HOWEVER, I have an additional question regarding the design of the function.

    Why does the function take "int" as input instead of "unsigned int", when we assume all negative numbers are NOT palindromic.

  • 13

    Very awesome question. Hope I could give you more votes. I have exactly the same question and I think it is unreasonable to define that all negative numbers are not palindromic.

  • 0

    I agree.
    If we needn't to handle negative numbers, why "-1" is given as an input?
    I think it's quite confusing.

  • 0

    Same question...... This question needs more explanation. -2147447412 should be okay to pass the test to me.

  • 1

    I agree with that. and the test case needs to be updated accordingly.

  • 30

    Palindrome by definition is defined as something that looks exactly identical read from either side. Negative numbers are all non-palindromes because of the negative sign. No negative number has a negative sign at the end as well and you cannot treat the number without its sign.

  • 0

    @rellik Still needs to be specified in the problem statement. The spoilers say "Could a negative number be a palindrome?" And of course, it could provided we ignore sign, which is a perfectly valid approach given that the problem statement doesn't spell out an specific expectation.

  • 0

    I agree. I think that the negative number always return false is unreasonable. Palindromes number is not Palindromes string. We can ignore negative sign and determine the number part if it is Palindromes.

  • 0

    Here thy have assumed that negative numbers are not palindromic.

  • 0

    I ran into the question! I used the helper function to test if this number out of integer range or not multiple times, all told no problem.

  • 0

    I ran into the same problem....I think -2147447412 should be okay to pass as a palindrome

  • 0

    this is ridiculous ! Can we have a proper explanation of what is expected from us? Leetcode sucks. And I agree with @goanpixie , -2147447412 should pass!!!

  • 0

    Agree with above all question, on what basis -2147447412 is not a palindromic number ??

    This isa values greater than Int32.min which is -2147483648

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.