An accepted Java code, easy to understand, don't know if a string takes extra space


  • 0
    X
        public boolean isPalindrome(int x) {
            if(x==0) return true;
            String str = Integer.toString(x);
            int len = str.length();
            for(int i=0; i<len/2; i++){
                if(str.charAt(i) != str.charAt(len-i-1)) return false;
            }
            return true;
        }
    }

Log in to reply
 

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