palindrome

Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Description: The value is -121 read from left to right. Read from right to left, 121-. So it's not a palindrome number. Example 3: Input: 10 Output: false Description: Read from right to left. The value is 01. So it's not a palindrome number. Advanced: Can you solve this problem by not converting integers to strings?Copy the code

Java code

class Solution {
    public boolean isPalindrome(int x) {
        if(x < 0) {
            return false;
        }
        
        int num = x;
        int rev = 0;
        while(x ! = 0){ //121 rev = rev*10 + x%10; //121 x = x/10; / / 0}if(num == rev){
            return true;
        }else{
            return false; }}}Copy the code