LeetCode-E- Palindrome Number

題意

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Subscribe to see which companies asked this question.

解法

實現

class Solution {
public:
    bool isPalindrome(int x) {
        if(x < 0) return false;
        long long y = x, r = x;
        long long p = y;
        long long z = 0;
        while(y != 0){
            int r = y % 10;
            z = z * 10 + r;
            y = y / 10;
        }
        return z == p;
    }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章