Leetcode 9:回文数

题目链接:回文数
刚刚注册了Leetcode试了一下,结果n次报错…没有考虑到负数的情况。

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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43894577/article/details/88921308