Created
May 6, 2020 14:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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