1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| class Solution { public boolean isPalindrome(int x) { String s = String.valueOf(x); char[] sr = s.toCharArray(); int i = 0; int j = s.length()-1; while(i < j) { if(sr[i] != sr[j]){ return false; } i++; j--; } return true; } }
class Solution { public boolean isPalindrome(int x) { if(x<0) return false; String reverse=new StringBuilder(x+"").reverse().toString(); int re; try{ re=Integer.parseInt(reverse); }catch(Exception e){ return false; } return re-x==0; } }
class Solution { public boolean isPalindrome(int x) { if(x<0) return false; String reverse=new StringBuilder(x+"").reverse().toString(); int re; try{ re=Integer.parseInt(reverse); }catch(Exception e){ return false; } return re-x==0; } }
|