My 6-line Java solution


  • 3
    H
    public class Solution {
        public boolean isPalindrome(int x){
            if(x < 0) return false;
            int reverse = 0, temp = x;
            while(x != 0){
                reverse = reverse * 10 + x % 10;
                x = x / 10;
            }
            return reverse == temp;
        }
    }

  • 0
    O

    reverse may overflow


Log in to reply
 

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