Skip to content

Commit dea919a

Browse files
authored
Create 9. Palindrome Number.java
depressingly confusing and brute-forcy
1 parent 2b1f5fb commit dea919a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

9. Palindrome Number.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution {
2+
public boolean isPalindrome(int x) {
3+
if (x < 0) return false;
4+
else if (x < 10) return true;
5+
else {
6+
int max_pow = (int)Math.log10(x);
7+
8+
for (int i = max_pow; i > 0; i--) {
9+
if ((Math.floor(x / Math.pow(10, i)) % 10) !=
10+
Math.floor((x % Math.pow(10, max_pow - i + 1)) / Math.pow(10, max_pow - i))) {
11+
return false;
12+
}
13+
}
14+
15+
return true;
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)