[Leetcode]Palindrome Number

class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0) return false;
        if(x<10) return true;
        int n = 0;
        int y = x;
        while(y){
            n++;
            y /= 10;
        }
        int left = pow(10, n - 1); 
        int right = 1;
        while(left>=right){
            if(x / left % 10 != x / right % 10) return false;
            left /= 10;
            right *= 10;
        }
        return true;
        
    }
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章