My accepted code,Is this simple enough?I don't know why we should consider the case of overflow.


  • 0
    L

    class Solution {
    public:
    bool isPalindrome(int x) {
    int y;
    int tmp;
    tmp=x;
    y=0;
    if(x<0)
    return false;
    while(tmp)
    {
    y=y*10;
    y+=tmp%10;
    tmp=tmp/10;
    }
    if(x==y)
    return true;
    return false;
    }
    };

    //if a number is reversible,it cannot overflow,so I think we don't need to consider this case,Am I right?


  • 0
    S

    I don't consider the overflow but I pass the program.


  • 0
    T

    your program is accepted ,but not consider these cases, such as 2147483647 or others!7463847412 will overflow...so your program will nor be stronger!


  • 0
    Z

    But in those cases the answer must be right, i.e., they cannot be palindrome. Since the original number is an integer, then if it is palindrome, the reversed number must also be an integer without any risk of overflow. Thus I agree with liyufeiat001


Log in to reply
 

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