Why consider overflow


  • 0
    T

    If a integer is palindrome number, then reversing this number will not cause overflow.
    In other words if overflow happened this number is not a palindrome number.
    So I am just wondering why we cannot just return false when overflow happens.
    Can someone explain to me? Thanks a lot!


  • 0
    M

    You can just return false in the event of overflow, but one method of solving this problem is to reverse the int and see if the two ints are equal to each other. If you don't attempt to catch the overflow exception, your program will crash before you can return anything, leaving you with a runtime error.

    When you "just return false when overflow happens," that's handling the overflow.


Log in to reply
 

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