Problem Description:
Given an integer x, return true if x is palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
For example, 121 is a palindrome while 123 is not.
Solution:
class Solution {
public boolean isPalindrome(int x) {
//negative numbers cannot be palindrome
if (x<0)
return false;
int rev=0;
int t=x;
//extracting each digit from the right,
//multiplying it with 10 and adding to reversed number
while(x!=0) {
rev = rev*10+(x%10);
x/=10;
}
return rev==t;
}
}