I have transferred the Number to String to solve the problem and got the AC, but I don't know whether it's fine.

  • 0

    Thanks for your viewing. I changed the number to string to solve this problem. Is it Ok?

    public class Solution {
        public boolean isPalindrome(int x) {
            Integer testing = x;
            String xS = testing.toString();
            if(xS.length() == 1) return true;
            while(xS.charAt(0) == xS.charAt(xS.length()-1)){
                xS = xS.substring(1,xS.length()-1);
                if(xS.length()<=1 ) return true;
            return false;

  • 0

    You need to use O(1) space instead of O(n) space. So, converting int to string is not an option.

Log in to reply

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