My accepted recursive solution using java, just for fun!!


  • 1
    Q
    public class Solution {
        static int num;
        public boolean isPalindrome(int x) {
            if(x < 0) return false;
            num = x;
            return helper(x);
        }
        public boolean helper(int x){
            if(x == 0 || x/10 == 0) return true;
            if(!helper(x/10)) return false;
            num = num/10;
            return x%10 == num%10;
        }
    }

  • 4
    S

    my friend , recursive solution needs extra space


Log in to reply
 

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