380ms accepted JAVA solution - what "no extra space" mean though?


  • 6
    S
    public boolean isPalindrome(int x) {
    
    if (x < 0) return false;
    else if (x < 10) return true;
    
    int n = (int) Math.log10(x);
    
    for (int i = n; i > n / 2; i--) {
    	if (x / (int) Math.pow(10, i) % 10 != x / (int) Math.pow(10, n - i) % 10)
    		return false;
    }
    
    return true;
    
    }

  • 0
    G

    It means you cannot dynamically allocate memory.


Log in to reply
 

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