【leetcode】 9. palindrome number

@requires_authorization
@author johnsondu
@create_time 2015.7.13 9:48
@url [palindrome-number](https://leetcode.com/problems/palindrome-number/)
/************************ * 分离出最左边和最右边的数 * 然后依次对比即可 ***********************/
class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0) return false;
        if(x < 10) return true;

        int base = 1;
        while(x / base >=10) base *= 10;

        while(x)
        {
            int ld = x / base;
            int rd = x % 10;
            if(ld != rd) return false;
            x -= ld * base;
            x /= 10;
            base /= 100;
        }
        return true;
    }
};

你可能感兴趣的:(LeetCode,Algorithm,palindrome)