11ms JAVA Solution


  • 0
    Y

    Move digits from original to the copy backward one by one and compare results.

        if (x<0) return false;
        if (x<10) return true;
        int y = 0; byte i = (byte)(x%10);
        if (i==0) return false;
        x /= 10;
        while (x>=y){
            if (x == y) return true;
            y = y*10+i;
            if (x == y) return true;
            i = (byte)(x%10);
            x /= 10;
        }
        return false;

Log in to reply
 

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