题目
链接
详情
实例
提示
题解
思路
将数字转换为字符串
然后将此字符串反转
将反转之后的字符串和反转前的字符串比较
若相等,则为回文数,否则不是回文数
代码
class Solution {
public:
bool isPalindrome(int x) {
char buff[100] = { 0 };
sprintf(buff, "%d", x);//将数字转换为字符串
string str_old = string(buff);
string str_new = str_old;
reverse(str_new.begin(), str_new.end());//字符串翻转
return !strcmp(str_old.c_str(), str_new.c_str());//字符串比较
}
};
标签:old,LeetCode9,str,字符串,new,buff,回文 From: https://www.cnblogs.com/EricsT/p/18530187