```
public class Solution {
public int reverse(int x) {
// Storing the number in StringBuffer
StringBuffer output = new StringBuffer();
// Check for Negative Number so that I can add negative sign later
boolean flag = false;
// If less than 0, it is negative. Ha!
if (x < 0) flag = true;
// From int to sb
output.append(Math.abs(x));
// Left Index
int i = 0;
// Right Index
int j = output.length()-1;
// Half way
while (i <= j) {
// Replace them every time until i crosses j
output = replace(output,i,j);
i++;
j--;
}
// Adding the negative sign and converting back to Integer
if (flag)
return -1 * (int)Long.parseLong(output.toString());
else return (int)Long.parseLong(output.toString());
}
/**
* Just some replace method
**/
public StringBuffer replace(StringBuffer input, int i, int j) {
char temp = input.charAt(i);
input.setCharAt(i, input.charAt(j));
input.setCharAt(j, temp);
return input;
}
}
```

Output timesout but I am making half the number of switches compared to other methods. Please help/