8 lines in java O(1)


  • 0
       public boolean isPalindrome(int x){
            if (x<0) return false;
            int num = x;
            int reverse = 0;
            while(num != 0){
                int remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num = num / 10;
            }
            return x == reverse;
        }
    

Log in to reply
 

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