leetcode——9——Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

class Solution {
public:
    bool isPalindrome(int x) {
     if (x < 0) return false;  
       int div = 1;  
     while (x / div >= 10) {  
         div *= 10;  
     }          
     while (x != 0) {  
        int l = x / div;  
        int r = x % 10;  
        if (l != r) return false;  
        x = (x % div) / 10;  
       div /= 100;  
     }  
      return true;  

    }
};


你可能感兴趣的:(LeetCode,算法题)