-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
executable file
·32 lines (30 loc) · 976 Bytes
/
Solution.java
File metadata and controls
executable file
·32 lines (30 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package $009;
/**
* @author Junlan Shuai[shuaijunlan@gmail.com].
* @date Created on 9:16 2018/3/20.
*/
public class Solution {
public boolean isPalindrome(int x) {
boolean check = x < 0 || (x != 0 && x % 10 ==0);
if (check){
return false;
}
int rev = 0;
while (x > rev){
rev = rev * 10 + x % 10;
x = x / 10;
}
boolean res = (rev == x) || (x == rev / 10);
return res;
}
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.isPalindrome(111));
System.out.println(solution.isPalindrome(1));
System.out.println(solution.isPalindrome(0));
System.out.println(solution.isPalindrome(1221));
System.out.println(solution.isPalindrome(15221));
System.out.println(solution.isPalindrome(15222221));
System.out.println(solution.isPalindrome(-111));
}
}