9. Palindrome Number
判断数字回文
class Solution {
public static boolean isPalindrome(int x
) {
if (x
< 0) {
return false;
}
List
<Integer> list
= new ArrayList<>();
int num
= x
;
while (x
> 0) {
int temp
= x
% 10;
list
.add(temp
);
x
/= 10;
}
int result
= 0;
for (int i
= 0; i
< list
.size(); i
++) {
result
= (result
* 10 + list
.get(i
));
}
if (result
== num
) {
return true;
} else {
return false;
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-51434.html