
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; } };
1、可以用long long int 保存解决溢出问题
2、题目中Do this without extra space.
是要求空间复杂度为O(1).
3、我们认为负数都不是回文数