Is helper function with an argument counted as extra space?


  • 0
    A

    My code (Java) is as follows:

    public class Solution {
        public boolean isPalindrome(int x) {
            if (x < 0) {
                return false;
            }
            if (x < 10) {
                return true;
            }
            return hasEqualFirstLastDigits(x + "");
        }
        
        public boolean hasEqualFirstLastDigits(String x) {
            if (x.length() == 1) {
                return true;
            }
            if (x.length() == 2) {
                return x.charAt(0) == x.charAt(1);
            }
            return (x.charAt(0) == x.charAt(x.length() - 1) && hasEqualFirstLastDigits(x.substring(1, x.length() - 1)));
        }
    }
    

    Is the helper function hasEqualFirstLastDigits(String x) counted as extra space?


Log in to reply
 

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