题解 | #牛的回文编号#
牛的回文编号
https://www.nowcoder.com/practice/f864e31a772240f1b4310fbdc27fad48
题目考察的知识点:判断一个数是否回文
题目解答方法的文字分析:判断一个数是否回文,将这个数翻转,然后判断是否相等。
本题解析所用的编程语言:c++
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param x int整型
* @return bool布尔型
*/
bool isPalindrome(int x)
{
// write code here
int tmp = x;
int y = 0;
while (tmp)
{
y *= 10;
y += tmp % 10;
tmp /= 10;
}
return x == y;
}
};
查看22道真题和解析