Palindrome Number

Monisha Mathew
1 min readMay 10, 2019

--

Question: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

Example 1:

Input: 121
Output: true

You may view the full question here.

Approach: Let’s try an approach which does not require us to convert the number into a string.

//Approach 1
//Runtime: 6ms
//Memory usage: 35.3MB
class Solution {
public boolean isPalindrome(int x) {
if(x>=0){
int rev = 0;
int temp = x;
while(temp!=0){
rev=(rev*10) + (temp%10);
temp=temp/10;
}
if(rev==x){
return true;
}
}
return false;
}
}

Find more posts here.

Cheers & Chao!

--

--