Skip to content

Instantly share code, notes, and snippets.

@AnjaliManhas
Created May 6, 2020 14:17
Show Gist options
  • Save AnjaliManhas/b8b5783897b79b0d03685904e64fbd75 to your computer and use it in GitHub Desktop.
Save AnjaliManhas/b8b5783897b79b0d03685904e64fbd75 to your computer and use it in GitHub Desktop.
Palindrome Number LeetCode- Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
class Solution {
public boolean isPalindrome(int x) {
int num = x;
boolean flag = false;
if (x < 0 || (x % 10 == 0 && x != 0)) return flag;
long r = 0;
while (x > 0) {
r = r * 10 + x % 10;
x /= 10;
}
if (r == num) {
flag = true;
return flag;
}
return flag;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment