18ms java solutions with recursive method


  • -1
    C

    public boolean isPalindrome(int x) {
    boolean is = true;
    String temp = "";
    if(x<0)
    is =false;
    else{
    temp =""+x;
    if(isPalindrome(temp))
    is = true;
    else
    is = false;
    }
    return is;

    }
    
    private boolean isPalindrome(String s){
    	if(s.length() ==0 || s.length() == 1)
    		return true;
    	if(s.charAt(0)==s.charAt(s.length()-1))
    		return isPalindrome(s.substring(1, s.length()-1));
    	
    	return false;
    	
    }

Log in to reply
 

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