leetcode problem 9: Palindrome Number

class Solution {
public:
    bool isPalindrome(int x) {
        int ret = 0;
        while (x > ret){
            int remainder = x % 10;
            if (remainder == 0 && ret == 0){
                return false;
            }
            ret *= 10;
            ret += remainder;
            if (x == ret){
                return true;
            }
            x /= 10;
        }
        if (x == ret){
            return true;
        }
        return false;
    }
};

 

posted @ 2017-09-17 21:48  nosaferyao  阅读(124)  评论(0编辑  收藏  举报