# Reverse Integer (Leetcode 7)

Problem Link: <https://leetcode.com/problems/reverse-integer/>

```python
class Solution:
    def reverse(self, x: int) -> int:
        
        if(x<-1*(2**31) or x>2**31):
            return 0
        
        if(x<0):
            negative=True
            x=-1*x
        else:
            negative=False
        
        ans=0
        n=x
        while(n):
            ans=10*ans+(n%10)
            n=n//10
        
        if(ans<-1*(2**31) or ans>2**31):
            return 0
        
        if(negative==True):
            return -1*ans
        else:
            return ans
            
```
