Palindrome Number 2015年6月23日
题目:
判断一个数是不是回文数
Determine whether an integer is a palindrome. Do this without extra space.
思路:借助上一道求整数逆序的思路,判断逆序后的数和原数是否相等就行。要注意,负数都不是回文数
11506 / 11506 test cases passed. Status: Accepted Runtime: 588 ms Submitted: 0 minutes ago
解答:
public class Solution { public boolean isPalindrome(int x) { int pal = 0; int origin = x; if(x<0) { return false; } while(x!=0) { pal = pal*10+x % 10; x /= 10; } return pal == origin; } }