Simple java solution

  • -3
        public boolean isPalindrome(int x) {
        if(x<0)return false;
        String s=String.valueOf(x);
        int i=0,k=s.length()-1;
            if(s.charAt(i++)!=s.charAt(k--)) return false;                 
        return true;

  • 1

    please be careful about the sentence:
    If you are thinking of converting the integer to string, note the restriction of using extra space.

Log in to reply

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