---
# System prepended metadata

title: Leetcode 9. Palindrome Number
tags: [Math]

---

# Leetcode 9. Palindrome Number
# math

``` java=

class Solution {
    public boolean isPalindrome(int x) {
        if(x<0||(x!=0 && x%10==0)) return false;
        
        int halfReverse=0;
        // 將一串數字拆成前半跟後半，只需反轉後半即可比較是否與前半相同 
        while(x > halfReverse){
            halfReverse=halfReverse*10+x%10;
            x/=10;
        }
        
        //      偶數位ex.123321   奇數位 ex.1235321
        return (halfReverse==x || halfReverse/10==x);
    }
}

```

###### tags: `Math`