首页 > 代码库 > [Leetcode] 9 - Palindrome Number

[Leetcode] 9 - Palindrome Number

原题链接: https://oj.leetcode.com/problems/palindrome-number/


非常非常简单的一道题。。。


class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0) return false;
        
        int ori = x;
        int rev = 0;
        
        while (x) {
            rev = rev * 10 + x % 10;
            x /= 10;
        }
        
        return (ori == rev);
    }
};


[Leetcode] 9 - Palindrome Number