What there is a Memory Limit Exceeded for my code?


  • 0
    Y

    My code is :

    class Solution {
    public:
    bool isPalindrome(int x) {
    int half_x = 0;

        if (x < 0) {return false;}
        if (x != 0 & x % 10 == 0) { return false; }
        
        while (x > half_x) {
            half_x = half_x * 10 + x % 10;
            x /= 10;
        } 
        
        return (x == half_x || x == half_x/10);
    }
    

    };

    I met a Memory Limit Exceeded for 2147483647. I think I only use two extra variables and the x and half_x are only two 5-digit numbers when 2147483647 is input. Then why there is an Exceeded? Thanks in advance for any answer.


  • 0

    This was just fixed, could you please try again?


  • 0
    Y

    Thanks! It works now.


Log in to reply
 

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