Skip to content

Commit e74e787

Browse files
committed
fd
1 parent 677392a commit e74e787

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

test/src/main/java/com/inuker/test/main.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,21 @@
2828
public class main {
2929

3030
public static void main(String[] args) {
31-
int[] range = new SearchForARange().searchRange(new int[] {
32-
1, 2, 3, 3, 4
33-
}, 3);
34-
for (int n : range) {
35-
System.out.print(n + " ");
36-
}
31+
System.out.println(isPalindrome(10));
3732
}
3833

39-
public int reverse(int x) {
40-
int sign = x > 0 ? 1 : -1;
41-
long y = Math.abs(x), z = 0;
42-
for ( ; y > 0; y /= 10) {
43-
z = z * 10 + y % 10;
34+
public static boolean isPalindrome(int x) {
35+
if (x < 0) {
36+
return false;
4437
}
45-
z *= sign;
46-
if (z > Integer.MAX_VALUE || z < Integer.MIN_VALUE) {
47-
throw new IllegalStateException();
38+
int t = 1;
39+
for (; t <= x / 10; t *= 10);
40+
41+
for (int k = 1; t > k; t /= 10, k *= 10) {
42+
if ((x / t) % 10 != (x / k) % 10) {
43+
return false;
44+
}
4845
}
49-
return (int) z;
46+
return true;
5047
}
5148
}

0 commit comments

Comments
 (0)