Skip to content

Commit b630930

Browse files
authored
Merge pull request #1736 from AP-Repositories/patch-19
Create 0009-palindrome-number.java
2 parents 4597e34 + 16aab63 commit b630930

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: java/0009-palindrome-number.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public boolean isPalindrome(int x) {
3+
if(x < 0) return false;
4+
5+
long div = 1;
6+
while(x >= 10 * div)
7+
div *= 10;
8+
9+
while(x > 0) {
10+
if(x / div != x % 10) return false;
11+
x = (int)((x % div) / 10);
12+
div = div / 100;
13+
}
14+
return true;
15+
}
16+
}

0 commit comments

Comments
 (0)