Palindrome Number
给一个数字, 问是不是回文数字. 写一个数字倒转的方法, 然后看一下即可.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class Solution { public boolean isPalindrome(int x) { if(x < 0) return false; return x == rev(x); } public int rev(int x) { int res = 0; while(x != 0){ res = res * 10 + x % 10; x = x / 10; } return res; } } |