Handle half digits


  • -1
    L
    public class Solution {
    public boolean isPalindrome(int x) {
        if(x<0) return false;
        int y=0;
        int temp=x;
        for(;temp!=0&&x>y;temp/=10)
            y=y*10+temp%10;
        return x==y||x==y/10;
    }
    

    }


  • 0
    A

    You reverse the whole number not just half digits


Log in to reply
 

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