Simply just modulo the input by 10, add it to a long-integer variable as the result.

Repeat. When the result is > max integer or < min integer, return 0. Hence, return the result as an integer

```
public class Solution {
public int reverse(int x) {
long result =0;
while(x != 0)
{
result = (result*10) + (x%10);
if(result > Integer.MAX_VALUE) return 0;
if(result < Integer.MIN_VALUE) return 0;
x = x/10;
}
return (int)result;
}
}
```