Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 19, 2014 02:31
Show Gist options
  • Save Cee/3b5decf51b8ca0884b28 to your computer and use it in GitHub Desktop.
Save Cee/3b5decf51b8ca0884b28 to your computer and use it in GitHub Desktop.
public class Solution {
public int reverse(int x) {
if (x == 0) return x;
int digit = 0;
if (x < 0){
digit = 1;
x = -x;
}
int ret = 0;
while (x > 0){
int temp = x % 10;
x = x / 10;
ret = ret * 10 + temp;
}
if (digit == 1) ret = -ret;
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment