leetcode 009 Palindrome Number

来源:互联网 发布:随你淘宝皇家小地主txt 编辑:程序博客网 时间:2024/05/22 06:57

9. Palindrome Number

 

 
 
Total Accepted: 119423 Total Submissions: 378311Difficulty: Easy

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

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;    }}


0 0
原创粉丝点击