Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

&nbsp;
Example 1:

Input: x = 123
Output: 321


Example 2:

Input: x = -123
Output: -321


Example 3:

Input: x = 120
Output: 21


&nbsp;
Constraints:


	-231 &lt;= x &lt;= 231 - 1


import bisect
class Solution:
    def reverse(self, x: int) -> int:

        flag = 0
        if x<0:
            x = abs(x)
            flag = 1
            
        l = [i for i in str(x)]
        l.reverse()
        
        ret = ''.join(l)
        ret = int(ret)
        
        if flag == 1:
            ret = ret*-1
            
        if ((ret >= (-(2**31))) and (ret<=((2**31)-1))):
            return ret
        else:
            return 0
class Solution {
    public int reverse(int x) {
        long reverse = 0;
        while (x != 0) {
            int digit = x % 10;
            reverse = reverse * 10 + digit;
            x = x / 10;
        }
        if (reverse > Integer.MAX_VALUE || reverse < Integer.MIN_VALUE) return 0;
        return (int) reverse;
    }
}
class Solution {
public:
    int reverse(int x) {
        long res = 0;
        while (abs(x) > 0) {
            res = (res + x % 10) * 10;
            x /= 10;
        }
        x < 0 ? res = res / 10 * -1 : res = res / 10;
        if (res < INT32_MIN || res > INT32_MAX) {
            res = 0;
        }
        return res;
    }
};
var reverse = function(x) {
    let val = Math.abs(x)
    let res = 0
    while(val !=0){
         res = (res*10) + val %10
         val = Math.floor(val/10)
    }
    if(x < 0)res = 0 - res
    return (res > ((2**31)-1) || res < (-2)**31) ? 0 : res 
};
Reverse Integer