-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path009_Palindrome_Number.java
68 lines (64 loc) · 1.32 KB
/
009_Palindrome_Number.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Solution {
public boolean isPalindrome(int x) {
if (x < 0)
return false;
int temp = x;
int len = 0;
while (temp != 0) {
temp /= 10;
len ++;
}
temp = x;
int left, right;
for (int i = 0; i < len / 2; i++) {
right = temp % 10;
left = temp / (int) Math.pow(10, len - 2 * i - 1);
left = left % 10;
if (left != right)
return false;
temp /= 10;
}
return true;
}
}
******************************************
class Solution {
public boolean isPalindrome(int x) {
int rev=0;
int d=1;
int temp=x;
if(x<0)
return false;
while(x!=0){
d=x%10;
rev=(rev*10)+d;
x/=10;
}
if(rev!=temp){
return false;
}
return true;
}
}
*******************************************
class Solution {
public boolean isPalindrome(int x) {
if(x < 0){
return false;
}
long revnum = 0;
int y = x;
while(x != 0){
int digit = x % 10;
if(revnum > Integer.MAX_VALUE){
return false;
}
revnum = revnum * 10 + digit;
x = x / 10;
}
if((int)revnum == y){
return true;
}
return false;
}
}