class Solution {
public:
bool isPalindrome(int x) {
if(x < 0)
return 0;//负数直接pass
int num = 1;
while(x/num > 9)
num *= 10;//看看是几位数
while(x != 0){//终止条件
int front = x/num;
int back = x%10;
if(front != back)
return 0;
x = (x%num)/10;//灵魂,%和/别搞反了
num /= 100;//迭代
}
return 1;
}
};
【LeetCode009】Palindrome Number
猜你喜欢
转载自blog.csdn.net/weixin_39458342/article/details/86652712
今日推荐
周排行