Skip to content

Commit

Permalink
Create Palindrome.java
Browse files Browse the repository at this point in the history
  • Loading branch information
o10a19 authored and x0lg0n committed Nov 1, 2024
1 parent 0ee97ed commit 6649d1c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Java/Palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Wrote a Boolean function program for checking wether a number is Palindrome or not also solution of leetcode Q9

class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}

int reversed = 0;
int original = x;

while (x > 0) {
int digit = x % 10;
reversed = reversed * 10 + digit;
x = x / 10;
}

return original == reversed;
}
}

0 comments on commit 6649d1c

Please sign in to comment.