classSolution {publicbooleanisPalindrome(int x) {// first instinct, parse into String, reverse, check is it the sameString s =String.valueOf(x);char c[] =s.toCharArray();for (int i =0; i <c.length/2; i++) {char temp = c[i]; c[i] = c[c.length- i -1]; c[c.length- i -1] = temp; }returnString.valueOf(c).equals(s); }}
Math
time: O(logn), log base is 10
space: O(1)
classSolution {publicbooleanisPalindrome(int x) {if (x <0) returnfalse;int y = x;int res =0;while (y !=0) { res = res*10+ y%10; y /=10; }return res == x; }}