How to handle the case of input integer ends with 0?


  • 0
    T

    Hi,

    Here is my solution.

        long long num = 0;
        
        while (abs(x) > 0){
            
            int res = x%10;
            
            num = num*10+res;
            
            if (num < INT_MIN || num > INT_MAX){
               return 0;
            }
            
            x /= 10;
            
        }
        
        return num;
    

    But if the input integer ends with 0, for example, x = 100.

    The output of my solution which is num will be 1 not 001, how to handle this case without using a string?

    Thanks.


Log in to reply
 

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