Skip to content

Commit c3040c4

Browse files
authored
Create 9. Palindrome Number
1 parent ab62391 commit c3040c4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

9. Palindrome Number

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class Solution {
2+
public boolean isPalindrome(int x) {
3+
if(x < 0){
4+
return false;
5+
}
6+
int xCopy = x;
7+
int mul = 1;
8+
while(xCopy/10 > 0){
9+
mul *= 10;
10+
xCopy /= 10;
11+
}
12+
while(x > 0){
13+
int h = x / mul;
14+
int l = x % 10;
15+
if(h != l){
16+
return false;
17+
}
18+
x = x % mul;
19+
x = x / 10;
20+
mul /= 100;
21+
}
22+
return true;
23+
}
24+
}

0 commit comments

Comments
 (0)