【leetcode】(每日抑题 9 回文数)

在这里插入图片描述
代码实现:
借鉴了一个极妙的方法,反转后两数相等

bool isPalindrome(int x){
    
    
    if(x<0)
    return false;//直接杀死负数

    long y=0;
    int temp=x;
    while(temp!=0){
    
    
        y=y*10+temp%10;
        temp/=10;
    }
    if(y==x)
    {
    
    
        return true;
    }
    return false;
}

猜你喜欢

转载自blog.csdn.net/qq_45657288/article/details/106086948