C++ simple solution


  • 0
    K
    class Solution {
    public:
        int reverse(int x) {
            int n=x,a,m=1,b;
            long int k=0;
            if (n<0)
            {
                m=-1;
                n*=m;
            }
            while (n>0)
            {
                a=n%10;
    
                k=k*10+a;
                n=n/10;
            }      
            k*=m;
            if (k<INT_MIN || k>INT_MAX)
            {return 0;}
            return k;
            
        }
    };
    

Log in to reply
 

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