Leetcode 9 Palindrome Number

来源:互联网 发布:故宫神思知乎 编辑:程序博客网 时间:2024/05/16 16:07
class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0){
            return false;  //所有的负数都不是回文数
        }
    long reverse = 0; //int有可能会越界
    int n = x;
    while(n != 0){
    reverse = reverse*10 + n %10;//这里应该用取余符号,一开始误用了/
    n = n/10;
    }
    if(reverse == x)
    return true;
    else return false;


    }
};