leetcode palindrome number

1,采用reverse的方法,来比较是不是palindrome

2,reverse number的方法!!

3,还要记得负数的情况

package Leetcode;

public class PalindromeNumber {
public boolean isPalindrome(int x) {
       if(x<0){
    	   return false;
       } 
       return x==reverse(x);
    }
public int reverse(int x){
	int temp=0;
	while(x!=0){
		temp=temp*10+x%10;
		x=x/10;
	}
	return temp;	
}
}

  

原文地址:https://www.cnblogs.com/lilyfindjobs/p/4051349.html