bool isPalindrome(int x) {
if(x < 0) return false;//负数没有回文数
if(x>=0 && x<10) return true;//0-9肯定为回文数
char str1[11], str2[11];//str1存储数字x的正序字符串,str2存储数字x的逆序字符串
sprintf(str1, "%d", x);
int len = 0;
while(x){
str2[len++] = '0' + x%10;
x /= 10;
}
str2[len] = '\0';
if(strcmp(str1, str2) == 0) return true;
return false;
}
判断回文数 (Palindrome Number<from LeetCode>)
最新推荐文章于 2025-05-05 08:35:54 发布