Created
September 14, 2017 17:32
-
-
Save cixuuz/b2112843e0d3cac89cc3b05310c11884 to your computer and use it in GitHub Desktop.
[9. Palindrome Number] #leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean isPalindrome(int x) { | |
if (x < 0 || (x!=0 && x%10==0)) return false; | |
int rev = 0; | |
while (x > rev) { | |
rev = rev * 10 + x % 10; | |
x = x/10; | |
} | |
return (x == rev || x == rev/10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment