Leetcode 9 Palindrome Number 数论

判断一个数是否是回文数

方法是将数回转,看回转的数和原数是否相同

 1 class Solution {
 2 public:
 3     bool isPalindrome(int x) {
 4         if(x < 0) return false;
 5         int _x = 0 ;
 6         int n = x;
 7         for(; x; x/= 10){
 8             _x = _x * 10 + x%10;
 9         }
10         return n == _x;
11     }
12 };

 

posted @ 2016-03-07 20:26  Breeze0806  阅读(205)  评论(0编辑  收藏  举报