(1) Reverse Integer - LeetCode

PHOTO EMBED

Thu Aug 12 2021 08:50:25 GMT+0000 (UTC)

Saved by @MorningStar #c++

class Solution {
public:
    int reverse(int x) {
        int y;
        int rev =0;
        if(x>INT_MIN || x<INT_MAX)
        {
            while(x)
        {
            y=x%10;
            x=x/10;
            if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0;
            if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0;
            rev=rev*10+y;
        }
        
        }
        return rev;
    }
};
content_copyCOPY

https://leetcode.com/problems/reverse-integer/