您的位置:首页 > 其它

Palindrome Number

2015-06-05 22:26 225 查看
class Solution {
public:
bool isPalindrome(int x) {
long long int ans=0;
int y=x;
while(y)
{
ans=ans*10+y%10;
y/=10;
}
if(ans==x&&x>=0)return 1;
return 0;
}
};


View Code
1、可以用long long int 保存解决溢出问题

2、题目中Do this without extra space.

是要求空间复杂度为O(1).

3、我们认为负数都不是回文数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: