题目:
Determine whether an integer is a palindrome. Do this without extra space.
思路:
做太多Array List,都忘了怎么处理 Int
基本上就是 取余数,除10,还有求 Int 数的位数
Code:
public boolean isPalindrome(int x) {
if(x<0) return false;
if(x<10) return true;
int base=1;
int leftDigit=0,rightDigit=0;
while(x/base>=10) base*=10;
while(base>1){
leftDigit = x/base;
rightDigit = x%10;
if(leftDigit!=rightDigit) return false;
x %= base;
base /= 100;
x /= 10;
}
return true;
}
备注:
Int 处理