Reverse Integer C++


  • 0
    M

    class Solution {
    public:
    int reverse(int x) {

        int temp = x;
        int rev = 0;
        
        while(abs(temp)>0){
        
            if(rev > (pow(2,31))/10 || rev < -(pow(2,31))/10){
                return 0;
            }
            rev = rev*10 + temp%10;
            temp = temp/10;
                
        }
        
        return rev;
        
    }
    

    };


Log in to reply
 

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