Reverse Integer(C++)

Given a 32-bit signed integer, reverse digits of an integer.

class Solution {

public:
    int reverse(int x)
    { 
        int ans=0,temp=0;
        while(x!=0)
        {
            temp=ans*10+x%10;
            if(temp/10!=ans)
                return 0;
            ans=temp;
            x/=10;
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/zrh_csdn/article/details/80326010
今日推荐