###### tags: `OTHER`, `Math` # MATH ## 9. [Palindrome Number](https://leetcode.com/problems/palindrome-number/) Beny ```csharp= public class Solution { public bool IsPalindrome(int x) { if(x < 0 || (x != 0 && x % 10 == 0)){ //若是負的或是尾數是0 且本身不是0 一定不是回文 return false; } int p = 0; while(p < x){ //當x>p結束 p = p * 10 + x % 10; //將原p的值往前移置10位數並取得x的尾數 x = x / 10; //移除x的尾數 } return (p == x || x == p/10);//因為長度會有奇數問題所以要多判斷一個除10 } } ```
×
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