My Java solution,tranfer the Integer to String


  • 0
    Q
    public boolean isPalindrome(int x){
    	if(x<0)
    		return false;
    	String s=Integer.toString(x);
    	int l=s.length();
    	for(int i=0;i<=(l/2);i++){
    		if(s.charAt(i)!=s.charAt(l-i-1)){
    			return false;
    		}
    	}
    	return true;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.