how to find palindrome numbers code example
Example 1: formula for finding a mathematical palindrome
how to check if a number is a palindrome or not
Example 2: check if palindrome
function isPalindrome(str) {
str = str.toLowerCase();
return str === str.split("").reverse().join("");
}
Example 3: determine whether integer is a palindrome
public class Solution {
public bool IsPalindrome(int x) {
if(x < 0 || (x % 10 == 0 && x != 0)) {
return false;
}
int revertedNumber = 0;
while(x > revertedNumber) {
revertedNumber = revertedNumber * 10 + x % 10;
x /= 10;
}
return x == revertedNumber || x == revertedNumber/10;
}
}