Link : Palindrome Number
Given an integer x
, return true if x
is palindrome integer.
An integer is a palindrome when it reads the same backward as forward.
For example, 121
is a palindrome while 123
is not.
class LC4 {
public boolean isPalindrome(int x) {
if(x < 0){
return false;
}
String str = String.valueOf(x);
int fullLength = str.length();
int halfLength = str.length()/2;
for(int i = 0; i < halfLength; i++){
if (str.charAt(i) != str.charAt(fullLength-1-i)){
return false;
}
}
return true;
}
}
//
//class Solution {
// public boolean isPalindrome(int x) {
// if(x<0){
// return false;
// }
// else{
// int tmp = x;
// int res=0;
// while(tmp>0){
// int t = tmp%10;
// res = res*10+t;
// tmp = tmp/10;
// }
// return res==x;
// }
// }
//}