Given an integer x, return true if x is a palindrome, and false otherwise.
Example 1:
Example 2:
Example 3:
Constraints:
Follow up:
public boolean isPalindrome(int x) {
// if x < 0
if(x < 0) return false;
if(x != 0 && x % 10 == 0) return false;
int reverse = 0;
// Loop till rev is smaller than num
while(x > reverse) {
int ld = x % 10;
reverse = (reverse * 10) + ld;
x = x / 10;
}
if(reverse == x) {
// When n has odd numers of digits
return true;
} else if(x == (reverse / 10)) {
// When n has odd numers of digits
return true;
} else {
return false;
}
}