Check if a given number is Palindrome. That is the number is the same when it reads forward and backward.
Example
5665
Solution
If we know how to reverse a number then it is easy to check it.
public class Solution {
public bool IsPalindrome(int x) {
if(x<0) return false;
if(x == reverse(x)) return true;
return false;
}
int reverse(int n)
{
int res = 0;
while(n != 0)
{
res = res * 10 + n%10;
n=n/10;
}
return res;
}
}