题目连接:Leetcode 009 Palindrome Number
解题思路:负数肯定不是对称数,而对于正数,用 Leetcode007中的方法将数翻转,如果等于原先的数,那么它就是对称数。
class Solution { public: bool isPalindrome(int x) { if (x < 0) return false; int ans = 0, t = x; while (t) { ans = ans * 10 + t % 10; t /= 10; } return ans == x; } };