LeetCode 7 Reverse Integer

题目

c++

class Solution {
public:
    int reverse(int x) {
        
        long long int ans=0;
    
    int tag=0;    
        while(x)
        {
            long long int y =x%10;
            x/=10;

            if(y==0&&tag==0)
                continue;
            else{
                ans=ans*10+y;
  
                tag=1;
            }
        }
        long long int z = (long long int) pow(2,31)-1;
        long long int y = z*-1;
        if(ans > z || ans < y)
        {
            ans=0;
        }

        
        return ans;
    }
};


posted @ 2019-06-03 09:03 Shendu.CC 阅读(...) 评论(...) 编辑 收藏