[leetcode]Palindrome Number

判断一个数字是否是回文,但是不能使用额外的空间- -!

不知道我定义一个div变量算不算额外空间-,-

class Solution {
public:
    bool isPalindrome(int x) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if(x < 0) return false;
        int div = 1;
        while(x / div >= 10) div = div * 10;
        while(x){
            if(x / div != x % 10) return false;
            x = (x % div) / 10;
            div /= 100;
        }
        return true;
    }
};

 

你可能感兴趣的:(LeetCode)