File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed
test/src/main/java/com/inuker/test Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change 28
28
public class main {
29
29
30
30
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 ));
37
32
}
38
33
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 ;
44
37
}
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
+ }
48
45
}
49
- return ( int ) z ;
46
+ return true ;
50
47
}
51
48
}
You can’t perform that action at this time.
0 commit comments