leetcode 009 Palindrome Number
9. Palindrome Number
Total Accepted: 119423 Total Submissions: 378311 Difficulty: Easy
Determine whether an integer is a palindrome. Do this without extra space.
Subscribe to see which companies asked this question
Have you met this question in a real interview?
package com.archer; /** * * @author Archer * 题解:判断是否是回文数,吧整数转换成String 然后就很简单了 */ public class Solution { public boolean isPalindrome(int x) { String tmp = x + ""; boolean odd = true ; int len = tmp.length(); int left;int right; if(len%2 == 0) odd =false; left = len/2 - 1; if(odd){ right = len/2 + 1; }else{ right = len/2; } while(left>=0 && right <len){ if(tmp.charAt(left) != tmp.charAt(right)) return false; left--;right++; } return true; } }