Skip to content

Commit

Permalink
9. Palindrome Number
Browse files Browse the repository at this point in the history
  • Loading branch information
SE-MahmoudAbdelaal committed May 20, 2024
1 parent c7cf655 commit b445d0b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions leetcode/easy/PalindromeNumber.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
public class PalinDrome {
public static boolean isPalindrome(int number) {
class Solution {
public boolean isPalindrome(int x) {
String s=Integer.toString(x);
int div=1;
int numberofpow=s.length()-2;
int firstDigit=(int)Math.pow(div, numberofpow);
int lastDigit=x%10;

if (number < 0)
return false;

int originalNumber = number;
int reversed = 0;

while (number != 0) {
int digit = number % 10;
reversed = reversed * 10 + digit;
number /= 10;

if (firstDigit==lastDigit) {
return true;

}
else{
return false;
}

}

return originalNumber == reversed;
}
}

0 comments on commit b445d0b

Please sign in to comment.