Skip to content

Commit 9e08b3a

Browse files
authored
Add files via upload
1 parent 3c27d63 commit 9e08b3a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Math/Palindrome_Number.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//LeetCode 9. Palindrome Number
2+
//Question - https://leetcode.com/problems/palindrome-number/
3+
4+
class Solution {
5+
public boolean isPalindrome(int x) {
6+
if(x < 0 || (x != 0 && x % 10 == 0)) return false;
7+
8+
int rev = 0;
9+
while(x > rev){
10+
rev = rev * 10 + (x % 10);
11+
x = x / 10;
12+
}
13+
14+
/*
15+
Two conditions to check if the number is a palindrome -
16+
1. even length number ==> x == rev
17+
2. odd length number ==> x == rev/10
18+
*/
19+
return (x == rev || x == rev / 10);
20+
}
21+
}

0 commit comments

Comments
 (0)