Extra 1 variable space, concise solution.


  • 2
    public class Solution {
        public boolean isPalindrome(int x) {
            if (x < 0 || (x != 0 && x % 10 == 0)) return false;
            else if (x < 10) return true;
            else {
                int half = 0;
                while (x > half) {
                    half = x%10 + half*10;
                    x /= 10;
                }
                if (x == half || half/10 == x)
                    return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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