Determine whether an integer is a palindrome. Do this without extra space.
思路是:先把int–>string–>char[]
public class Solution {
public boolean isPalindrome(int x) {
String s=x+"";
char[] c=s.toCharArray();
int i=0,j=c.length-1;
while(i<j){
if(c[i]!=c[j]) return false;
i++;
j--;
}
return true;
}
}
类似的还有判断字符串是不是回文串,只需直接把string转换成char[] 就可以了。