# 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`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up