Created
December 22, 2015 00:31
-
-
Save rdtr/c36e54890cbb7b9ddcf2 to your computer and use it in GitHub Desktop.
algorithm_math_palindrome_number.java
This file contains 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
public class Solution { | |
public boolean isPalindrome(int x) { | |
if (x < 0) return false; | |
else if (x >= 0 && x < 10) return true; | |
int originalX = x; | |
int reversedX = 0; | |
while (x > 0) { | |
reversedX = reversedX * 10 + x % 10; | |
x /= 10; | |
} | |
return originalX == reversedX; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment